Thursday 15 July 2010

Python program not displaying gateway and network ip -



Python program not displaying gateway and network ip -

import socket import struct def get_default_gateway_linux(): open("/proc/net/route") fh: line in fh: fields = line.strip().split() if fields[1] != '00000000' or not int(fields[3], 16) & 2: go on homecoming socket.inet_ntoa(struct.pack("<l", int(fields[2], 16))) def getnetworkip(): s = socket.socket(socket.af_inet, socket.sock_dgram) s.connect(('bt', 0)) homecoming s.getsockname()[0] print "your machine ip has been detected "+getnetworkip() print "your gateway ip has been detected "+get_default_gateway_linux()

the above code neither shows error nor output when executed in backtrack 5 r3 please help me regarding code!

your 2 print statements tabbed/spaced. remove them , work have confirmed work on centos 6.5:

def getnetworkip(): s = socket.socket(socket.af_inet, socket.sock_dgram) s.connect(('localhost',0)) homecoming s.getsockname()[0] print "your machine ip has been detected "+getnetworkip() print "your gateway ip has been detected "+get_default_gateway_linux()

python ip output local gateway

No comments:

Post a Comment