aMule Forum

English => en_Linux => Topic started by: Reorder on January 11, 2011, 08:18:42 PM

Title: Error when running python script to dump nodes.dat contents
Post by: Reorder on January 11, 2011, 08:18:42 PM
I tried to run the python script from the wiki (http://wiki.amule.org/index.php/Nodes.dat_file#Script_for_dumping_nodes.dat) to dump the contents of nodes.dat, but I get an error:
Code: [Select]
line 36
    ipaddr = '%d.%d.%d.%d' % (ip1, ip2, ip3, ip4)
    ^
IndentationError: unexpected indent

Is there something obvious that I'm doing wrong?  I know squat about python, or it's indentation rules.

(Ubuntu 10.04 -- Python 2.6.5 -- aMule 2.2.6)
Title: Re: Error when running python script to dump nodes.dat contents
Post by: Stu Redman on January 11, 2011, 09:05:33 PM
Just use fileview (from src/utils/fileview), you have to build it first though.
Or look at the wiki history and try the script before someone "improved" it a few versions ago.  :)
Title: Re: Error when running python script to dump nodes.dat contents
Post by: Reorder on January 12, 2011, 01:20:20 AM
Or look at the wiki history and try the script before someone "improved" it a view versions ago.  :)

Thanks for the help.

Looking at the older versions gave me clues as to what the formatting/indentations problems were.
I ended up fiddling with those and some other minor things and getting the script to work.  I uploaded my changes to the wiki.  Hopefully the thing is portable.

(I am not a programmer, so maybe it's just me.  But I swear that sometimes folks code things in a willfully hard-to-read manner.  Either that or they are working on monitors/terminals that only show two or three lines of code at a time so they have to pack everything as close together as possible.)

If anyone cares, here's the script I uploaded:

Code: [Select]
#!/usr/bin/env python
# this code belongs to public domain
# requires nodes.dat filename passed as argument
 
import struct
import sys

version = 0
count = 0

# check number of command line arguments
if len(sys.argv) != 2:
    sys.exit("Please supply a nodes.dat file!")
 
nodefile = open(sys.argv[1], 'r')

(count,) = struct.unpack("<I", nodefile.read(4))
if (count == 0):
    (version,) = struct.unpack("<I", nodefile.read(4))
    (count,)   = struct.unpack("<I", nodefile.read(4))

if (version >= 0 & version < 3):
    print 'Nodes.dat file version = %d' %(version)
    print 'Node count = %d' %(count)
    print ' '
    if (version == 0):
        print ' idx type  IP address      udp   tcp'
    else :
        print ' idx Ver IP address        udp   tcp kadUDPKey        verified'

    for i in xrange(count):
        if (version == 0):
            (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)
        else :
            (clientid, ip1, ip2, ip3, ip4, udpport, tcpport, type,  kadUDPkey,
             verified) = struct.unpack("<16s4BHHBQB", nodefile.read(34))
            ipaddr = '%d.%d.%d.%d' % (ip1, ip2, ip3, ip4)
            if (verified == 0): verf='N'
            else : verf='Y'
            print '%4d %3d %-15s %5d %5d %16x %s' % (i, type, ipaddr, udpport,
                                                     tcpport, kadUDPkey, verf)

else :
    print 'Cannot handle nodes.dat version %d !' (version)

nodefile.close()
Title: Re: Error when running python script to dump nodes.dat contents
Post by: Stu Redman on January 12, 2011, 11:20:04 PM
Thank you!