Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P10821
(An Untitled Masterwork)
Active
Public
Actions
Authored by
kolbert
on Mar 30 2020, 10:50 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F31716108: raw.txt
Mar 30 2020, 10:50 PM
2020-03-30 22:50:55 (UTC+0)
Subscribers
None
#!/usr/bin/env python
import
json
import
requests
import
sys
from
requests_oauthlib
import
OAuth1
#Script takes in the block length as a command-line argument
script
,
length
=
sys
.
argv
METAWIKI_API
=
'https://meta.wikimedia.org/w/api.php'
def
make_request
(
api
,
payload
,
post
=
False
):
config
=
json
.
loads
(
open
(
'config.json'
)
.
read
())
auth
=
OAuth1
(
config
[
'customer_token'
],
config
[
'customer_secret'
],
config
[
'access_token'
],
config
[
'access_secret'
])
if
post
:
return
requests
.
post
(
api
,
data
=
payload
,
auth
=
auth
)
else
:
return
requests
.
get
(
api
,
params
=
payload
,
auth
=
auth
)
ips
=
open
(
'ips.txt'
,
'r'
)
.
read
()
.
split
(
'
\n
'
)
for
ip
in
ips
:
print
(
'Blocking
%s
, open proxy'
%
ip
)
r
=
make_request
(
METAWIKI_API
,
{
"action"
:
"query"
,
"format"
:
"json"
,
"meta"
:
"tokens"
,
"type"
:
"csrf"
})
token
=
r
.
json
()[
'query'
][
'tokens'
][
'csrftoken'
]
r
=
make_request
(
METAWIKI_API
,
{
"action"
:
"globalblock"
,
"format"
:
"json"
,
"target"
:
ip
,
"expiry"
:
length
,
"reason"
:
"[[m:NOP|Open proxy]]"
,
"token"
:
token
})
r
=
make_request
(
METAWIKI_API
,
{
"action"
:
"query"
,
"format"
:
"json"
,
"meta"
:
"tokens"
,
"type"
:
"csrf"
})
token
=
r
.
json
()[
'query'
][
'tokens'
][
'csrftoken'
]
r
=
make_request
(
METAWIKI_API
,
{
"action"
:
"block"
,
"format"
:
"json"
,
"target"
:
ip
,
"expiry"
:
length
,
"reason"
:
"[[m:NOP|Open proxy]]"
,
"nocreate"
:
1
,
"autoblock"
:
1
,
"token"
:
token
})
ips
.
close
()
Event Timeline
kolbert
created this paste.
Mar 30 2020, 10:50 PM
2020-03-30 22:50:55 (UTC+0)
Log In to Comment