Skip to content

Instantly share code, notes, and snippets.

@corck corck/main.py forked from ixje/main.py
Created Oct 24, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.