#!/usr/bin/env python
# this code belongs to public domain
# 
# (from http://www.amule.org/wiki/index.php/Nodes.dat_file)
#

import struct, sys

if len(sys.argv) != 2 :
 sys.exit("usage: dumpnodes.py nodes_dat_file")



# my thefilename;
thefilename = sys.argv[1]
print 'Reading file ', thefilename
nodefile = open(thefilename, 'r')
(count,) = struct.unpack("<I", nodefile.read(4)) 

print ' idx type    ip address    udp   tcp'
for i in xrange(count):
  (clientid, ip1, ip2, ip3, ip4, udpport, tcpport, type) = struct.unpack("<16s4BHHB", nodefile.read(25))
  ipaddr = '%d.%d.%d.%d' % (ip1, ip2, ip3, ip4)
  print '%4d %4d %-15s %5d %5d' % (i, type, ipaddr, udpport, tcpport)
nodefile.close()

