screenlets-dev team mailing list archive
-
screenlets-dev team
-
Mailing list archive
-
Message #00334
[Bug 618868] Re: sysmonitor screenlet fails to find the computer's IP address
Yes, there is another way: using the command ip from the net-tools package instead of ifconfig. This package is installed by default in Ubuntu. Don't know for other distributions.
Use it like this:
$ ip addr show
On my machine, it prints this:
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:25:b3:c0:b6:86 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:21:6a:6c:de:18 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.8/24 brd 192.168.1.255 scope global wlan0
inet6 fe80::221:6aff:fe6c:de18/64 scope link
valid_lft forever preferred_lft forever
4: vboxnet0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
You can narrow it to what is interresting with:
$ ip -o -4 addr show
1: lo inet 127.0.0.1/8 scope host lo
3: wlan0 inet 192.168.1.8/24 brd 192.168.1.255 scope global wlan0
So basically your function stays the same.
I've tried to use the python socket module directly but it gives an ip
address even if the connection is lost for some reason:
>>> import socket
>>> socket.gethostbyname_ex(socket.gethostname())[2][0]
'192.168.1.8'
So I suppose your best bet is to go the 'ip addr show' way.
--
sysmonitor screenlet fails to find the computer's IP address
https://bugs.launchpad.net/bugs/618868
You received this bug notification because you are a member of
Screenlets Dev Team, which is subscribed to Screenlets.