Open GoogleCodeExporter opened 9 years ago
For what it's worth, http://alastairs-place.net/projects/netifaces/ is a
library with what looks like similar goals to yours.
Original comment by phi...@cloudera.com
on 13 May 2013 at 11:47
Linux implementeation committed as revision 259cf1979d3a.
Original comment by g.rodola
on 15 May 2013 at 11:42
FreeBSD implementation committed in revision f1e8283cb6a4.
Original comment by g.rodola
on 17 May 2013 at 1:57
I can't see how can I get a list of all available network interface ids?
I am looking into some call to return ["lo", "eth0"] list in one step.
The next I'd like to do is to get all IPs for each interface "by-id".
Original comment by techtonik@gmail.com
on 15 Dec 2013 at 12:43
Probably a hack, but I found this:
$ cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 9108970 99862 0 0 0 0 0 0 9108970 99862 0 0 0 0 0 0
eth0: 350377139 290149 0 0 0 0 0 0 31993244 236043 0 0 0 0 0 0
Original comment by techtonik@gmail.com
on 15 Dec 2013 at 12:46
So, I an list those as:
ifaces = []
with open("/proc/net/dev", "rb") as netstat:
for i, line in enumerate(netstat):
if i < 2: # skip first two header lines
continue
parts = line.split(':')
ifaces += [parts[0].strip()]
print ifaces
Original comment by techtonik@gmail.com
on 15 Dec 2013 at 12:49
I started developing this feature in a separate branch so that's why it is not
available yet (Windows, OSX and Solaris implementations are still missing).
If you want a list of all available NIC names you can already do that by using:
>>> import psutil
>>> list(psutil.net_io_counters(pernic=True))
['lo', 'wlan0', 'eth1']
>>>
Obviously you won't get the associated IP addresses.
Original comment by g.rodola
on 16 Dec 2013 at 1:30
This interface is very hackish. =)
Original comment by techtonik@gmail.com
on 16 Dec 2013 at 3:45
The main goal of net_io_counters() is to provide IO stats, not NIC names,
that's why "list(psutil.net_io_counters(pernic=True))" looks hackish.
Original comment by g.rodola
on 16 Dec 2013 at 3:51
I found an easy way to list all NICs:
$ ls /sys/class/net
eth0 lo
Original comment by techtonik@gmail.com
on 16 Dec 2013 at 4:48
Or more pythonically:
>>> import os
>>> os.listdir('/sys/class/net')
['lo', 'eth0']
The only problem now is to get IPs for those.
Original comment by techtonik@gmail.com
on 16 Dec 2013 at 4:50
The purpose of this ticket is not to provide an API to retrieve NIC names.
We already have a function which can indirectly be used to do that and when
this issue will be closed as fixed we'll have 2.
I don't think providing yet another (3) API for the same functionality is a
good idea.
We'll just use psutil.net_ifaces().keys() and be done with it.
Original comment by g.rodola
on 16 Dec 2013 at 4:52
psutil has been migrated from Google Code to Github (see:
http://grodola.blogspot.com/2014/05/goodbye-google-code-im-moving-to-github.html
).
Please do NOT reply here but use this instead:
https://github.com/giampaolo/psutil/issues/376
Original comment by g.rodola
on 26 May 2014 at 3:07
Original comment by g.rodola
on 3 Jun 2014 at 11:15
Original issue reported on code.google.com by
g.rodola
on 10 May 2013 at 1:16