Skip to content

Instantly share code, notes, and snippets.

@corck
Created October 24, 2019 07:22
Show Gist options
  • Save corck/8c929d685df637a7e66a763bb2fadcf1 to your computer and use it in GitHub Desktop.
Save corck/8c929d685df637a7e66a763bb2fadcf1 to your computer and use it in GitHub Desktop.
find connected NEO nodes from coz monitor RPC list
import requests
import ipaddress
def get_endpoints():
endpoints = []
response = requests.get("https://raw.githubusercontent.com/CityOfZion/neo-mon/master/docs/assets/mainnet.json")
response.raise_for_status()
if response.status_code == 200:
results = response.json()
for site in results['sites']:
if site["type"] == "RPC":
if "address" in site:
endpoints.append(f"{site['protocol']}://{site['address']}:{site['port']}")
continue
if "url" in site:
endpoints.append(f"{site['protocol']}://{site['url']}:{site['port']}")
return endpoints
def main():
payload = {
"jsonrpc": "2.0",
"method": "getpeers",
"params": [],
"id": 1
}
addresses = []
for addr in get_endpoints():
try:
response = requests.post(addr, json=payload, timeout=3)
except Exception:
continue
response.raise_for_status()
if response.status_code == 200:
if 'result' in response.json():
result = response.json()['result']
if 'connected' in result:
for entry in result['connected']:
addresses.append(f"{entry['address']}:{entry['port']}")
print(list(set(addresses)))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment