How do I determine what ip range a device is using?
<p>This is kind of a weird problem, basically I have a computer connected to a machine via ethernet cable. There is no other network or internet access. The machine sets up a network which allows you to telnet into it. </p>

<p>I need the simplest way possible to determine the ip range the device is using. This would be turned into a python script. It is not just the obvious 192.168.x.x</p>

<p>I'm looking at the 'arp' command, but also a library called 'netifaces'. I'm not sure if there's something simpler I could use. It has to work for Linux, OSX and Windows. The machine is running an android OS</p>

<p>Basically, I just need to be able to determine what ip ranges the device is currently using in the simplest possible way. </p>

<p>The command 'arp -a' seems to be the most promising right now. </p>

<p>Try this </p>

<pre><code>import socket
import fcntl
import struct

def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(
        s.fileno(),
        0x8915,  # SIOCGIFADDR
        struct.pack('256s', ifname[:15])
    )[20:24])

get_ip_address('eth0')  # '192.168.0.110'
</code></pre>

python networking