aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Author Topic: Error when running python script to dump nodes.dat contents  (Read 8106 times)

Reorder

  • Newbie
  • Karma: 1
  • Offline Offline
  • Posts: 2
Error when running python script to dump nodes.dat contents
« on: January 11, 2011, 08:18:42 PM »

I tried to run the python script from the wiki 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)
Logged

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: Error when running python script to dump nodes.dat contents
« Reply #1 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.  :)
« Last Edit: January 12, 2011, 11:14:02 PM by Stu Redman »
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

Reorder

  • Newbie
  • Karma: 1
  • Offline Offline
  • Posts: 2
Re: Error when running python script to dump nodes.dat contents
« Reply #2 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()
Logged

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: Error when running python script to dump nodes.dat contents
« Reply #3 on: January 12, 2011, 11:20:04 PM »

Thank you!
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon