Getting LAN IP address of local computer

Using Python to get the LAN IP address of the local computer:

If we use:

import socket

we will get '' which may not be what we want due to the presence of the hosts file.

We could use:

import socket

we will get something like '192.168.0.xxx' which is more likely what we want.

The above code fragment works in Windows XP, may need adjustment in getting the host name in other OS.

No comments: