bat-serjo / pyiface Goto Github PK
View Code? Open in Web Editor NEWPython module to control network interfaces.
License: GNU General Public License v3.0
Python module to control network interfaces.
License: GNU General Public License v3.0
I can read out the interfaces but if I want to get the addr property I get an error message. Here is a minimal example in the python console:
>>> import pyiface
>>> pyiface.getIfaces()[0].addr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pyiface/iface.py", line 291, in addr
ifr = self.__newIfreqWithName()
File "/usr/local/lib/python2.7/dist-packages/pyiface/iface.py", line 181, in __newIfreqWithName
ifr.ifr_name = self._name
TypeError: expected c_ubyte_Array_16 instance, got str
Any thoughts on what is going on? :)
Thanks!
Hi,
nice module, works as a charm for me on Linux. On Solaris I don't retrieve any of the machine's interfaces with pyiface.getIfaces().
Chances are that you don't have access to the Solaris platform, but just to let you and potential users know:
$ uname -a
SunOS dev001 5.10 Generic_137111-07 sun4u sparc SUNW,Sun-Fire-V490 Solaris
0 $ ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
ce0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet xx.yy.32.85 netmask fffff000 broadcast xx.yy.47.255
qfe0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet xx.yy.48.85 netmask fffff000 broadcast xx.yy.63.255
0 $ python2.7 -i -c 'import pyiface'
>>> pyiface.getIfaces()
[]
I guess that's due to some various platform-specific intricacies. Unfortunately I can't currently look into this any more but the error that is raised from Interface.__doIoctl(...) is
>>> pyiface.getIfaces()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyiface/iface.py", line 388, in getIfaces
ifa = Interface(idx=i)
File "pyiface/iface.py", line 174, in __init__
self._name = self.name
File "pyiface/iface.py", line 227, in name
self.__doIoctl(ifr, SIOCGIFNAME)
File "pyiface/iface.py", line 191, in __doIoctl
raise ioException
IOError: [Errno 22] Invalid argument
(your actual code doesn't raise and suppresses the exception I just quick-and-dirty changed that to get an idea)
Would be great if your approach could work cross-platform (Windows?).
I've seen, that version in setup.py
hasn't changed since 0.0.6 and there are no git tags. What do you think about using setuptools_scm?
Thanks for the fantastic module!
I run into an issue when attempting to change the MAC address on an interface. Can you tell me about the code path you expected this to follow? I see that sockaddr_dl wasn't used. Is this functionality still pending?
Traceback (most recent call last):
File "", line 1, in
File "/root/ConfigApp/speedy/lib/python2.7/site-packages/pyiface/iface.py", line 295, in hwaddr
ifr.data.ifr_hwaddr.sin_addr.s_addr = val
AttributeError: 'sockaddr' object has no attribute 'sin_addr'
@bat-serjo IPv6 doesn't work
t.addr = (socket.AF_INET6, '2001:db8:0:0:0:ff00:42:8329')
File "/workspace/PyIface/pyiface/iface.py", line 314, in addr
ifr.data.ifr_addr = self.__sockaddrFromTuple(val)
File "/workspace/PyIface/pyiface/iface.py", line 365, in __sockaddrFromTuple
inVal[1]))
TypeError: expected in6_u instance, got bytes
Also If I try to get addr for an interface it never returns IPv6 address, only IPv4 or None
>>> import pyiface
>>> ff = pyiface.Interface(name='eth0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pyiface/iface.py", line 186, in __init__
self._index = self.index
File "/usr/local/lib/python2.7/dist-packages/pyiface/iface.py", line 233, in index
self.__doIoctl(ifr, SIOCGIFINDEX)
File "/usr/local/lib/python2.7/dist-packages/pyiface/iface.py", line 195, in __doIoctl
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) as skt:
AttributeError: __exit__
>>> exit()
> # pip list | grep pyiface
> pyiface 0.0.9
I tried to make the instance pyiface.interface
but it was NOT made.
When I use this module in version 0.0.7, it have worked.
I would need to create local virtual interfaces and assign them IPs for testing purposes. Would be veeery useful to be able to do that in Python!
README has a little documentation glitch:
"
eth0 = PyIface.Interface('eth0')
"
but
>>> pyiface.Interface("eth0").name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyiface/iface.py", line 174, in __init__
self._name = self.name
File "pyiface/iface.py", line 226, in name
ifr.data.ifr_ifindex = self._index
TypeError: an integer is required
>>>
>>> pyiface.Interface(name="eth0") # use named parameter
<pyiface.iface.Interface object at 0x7f510151dc50>
>>> pyiface.Interface(name="eth0").name
'eth0'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.