Skip to content

Instantly share code, notes, and snippets.

@pstjuste
Last active August 25, 2018 17:16
Show Gist options
  • Save pstjuste/5528389 to your computer and use it in GitHub Desktop.
Save pstjuste/5528389 to your computer and use it in GitHub Desktop.
This code runs on appengine and provides a simple IP lookup service for my machines.
#!/usr/bin/env python
"""
This link below is where to get a list of Gnutella web caches
http://gwebcaches.pongwar.com/gnutella.html
This is an example of how to obtain a list of Gnutella nodes
curl 'http://gwc.gofoxy.net:2108/gwc/cgi-bin/fc?hostfile=1'
"""
import socket, sys
socket.setdefaulttimeout(5)
request = ("GNUTELLA CONNECT/0.6\r\n"
"User-Agent: LimeWire (crawl)\r\n"
"X-Ultrapeer: False\r\n"
"Query-Routing: 0.1\r\n"
"Crawler: 0.1\r\n\r\n")
def main():
peers = [line for line in open(sys.argv[1])]
for peer in peers:
try:
makecall(peer, peers)
except Exception as ex:
print "FAILED ", peer, ex
def makecall(endpoint, peers):
host, port = endpoint.strip().split(':')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host,int(port)))
sock.send(request)
response = sock.recv(4096)
sock.close()
print response
for line in response.split('\n'):
if line.startswith('Peers'):
peers = peers + line[7:].split(',')
elif line.startswith('X-Try-Ultrapeers'):
peers = peers + line[18:].split(',')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment