Skip to content

Instantly share code, notes, and snippets.

@jin10086
Created July 14, 2020 01:47
Show Gist options
  • Save jin10086/e20688e33f2558cdbf7f5d0664f24719 to your computer and use it in GitHub Desktop.
Save jin10086/e20688e33f2558cdbf7f5d0664f24719 to your computer and use it in GitHub Desktop.
import requests
import time
from web3.auto import w3
headers = {
"authority": "ethernodes.org",
"accept": "application/json, text/javascript, */*; q=0.01",
"x-requested-with": "XMLHttpRequest",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36",
"referer": "https://ethernodes.org/nodes",
"accept-language": "zh-CN,zh;q=0.9,zh-TW;q=0.8",
}
s = requests.Session()
s.headers = headers
def getnodelist():
start = 0
i = 1
nodes = []
while True:
print(f"start:{start} i:{i}")
params = (
("draw", i),
("columns[0][data]", "id"),
("columns[0][name]", ""),
("columns[0][searchable]", "true"),
("columns[0][orderable]", "true"),
("columns[0][search][value]", ""),
("columns[0][search][regex]", "false"),
("columns[1][data]", "host"),
("columns[1][name]", ""),
("columns[1][searchable]", "true"),
("columns[1][orderable]", "true"),
("columns[1][search][value]", ""),
("columns[1][search][regex]", "false"),
("columns[2][data]", "isp"),
("columns[2][name]", ""),
("columns[2][searchable]", "true"),
("columns[2][orderable]", "true"),
("columns[2][search][value]", ""),
("columns[2][search][regex]", "false"),
("columns[3][data]", "country"),
("columns[3][name]", ""),
("columns[3][searchable]", "true"),
("columns[3][orderable]", "true"),
("columns[3][search][value]", ""),
("columns[3][search][regex]", "false"),
("columns[4][data]", "client"),
("columns[4][name]", ""),
("columns[4][searchable]", "true"),
("columns[4][orderable]", "true"),
("columns[4][search][value]", ""),
("columns[4][search][regex]", "false"),
("columns[5][data]", "clientVersion"),
("columns[5][name]", ""),
("columns[5][searchable]", "true"),
("columns[5][orderable]", "true"),
("columns[5][search][value]", ""),
("columns[5][search][regex]", "false"),
("columns[6][data]", "os"),
("columns[6][name]", ""),
("columns[6][searchable]", "true"),
("columns[6][orderable]", "true"),
("columns[6][search][value]", ""),
("columns[6][search][regex]", "false"),
("columns[7][data]", "lastUpdate"),
("columns[7][name]", ""),
("columns[7][searchable]", "true"),
("columns[7][orderable]", "true"),
("columns[7][search][value]", ""),
("columns[7][search][regex]", "false"),
("columns[8][data]", "inSync"),
("columns[8][name]", ""),
("columns[8][searchable]", "true"),
("columns[8][orderable]", "true"),
("columns[8][search][value]", ""),
("columns[8][search][regex]", "false"),
("order[0][column]", "0"),
("order[0][dir]", "asc"),
("start", start),
("length", "100"),
("search[value]", ""),
("search[regex]", "false"),
("_", f"{int(time.time()*1000)}"),
)
z1 = s.get("https://ethernodes.org/data", params=params)
data = z1.json()["data"]
_nodes = [f'enode://{i["id"]}@{i["host"]}:{i["port"]}' for i in data]
nodes.extend(_nodes)
recordsTotal = z1.json()["recordsTotal"]
if start > recordsTotal - 100:
break
start += 100
i += 1
return nodes
if __name__ == "__main__":
n = getnodelist()
print(f"peer count:{len(n)}")
for i in n:
w3.geth.admin.add_peer(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment