ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

ifcfg fails on Windows #58

Closed mtHB closed 3 years ago

mtHB commented 3 years ago

Hey there! Please take into account that this is my second issue I write on github so please help me improve my issue creation!


So I tried to get my local IP adress with ifcfg 0.21 on Windows 10 and python 3.7.

import ifcfg

for name, interface in ifcfg.interfaces().items():
    print (interface['device'])
    print (interface['inet'])
    print (interface['inet4'])
    print (interface['inet6'])
    print (interface['netmask'])
    print (interface['broadcast'])

Output:

ethernet-adapter ethernet
None
[]
[]
None
Traceback (most recent call last):
  File "C:/Users/foo/AppData/Roaming/JetBrains/PyCharmCE2020.3/scratches/scratch.py", line 10, in <module>
    print (interface['broadcast'])
KeyError: 'broadcast'

Process finished with exit code 1

At first I saw that the example in the README is for Python 2 due to the missing brackets in the print statement. Maybe you want to highlight that.

Also ifcfg seems to have problems with ipconfig on Windows systems. All values I checked where either empty lists or None objects.

Also the 'broadcast' key was not found and did raise a KeyError.

Am I overlooking something?

mtHB commented 3 years ago

After short investigation I saw that the parser is looking for certain patterns.

My system language is german so it probably won't find those patterns.

benjaoming commented 3 years ago

Thanks so much for the report @mtHB ! This repository is not so strict about the format for reporting. I think you made it quite understandable what the issue is.

But it's most definitely a duplicate of #18 -- which has been open for quite a long time. I'm not sure if anyone would want to work on it, since it has been open for a very long time.

But if there is a way to invoke ipconfig on Windows and guarantee English output, that would be the preferable fix.

I'm closing this, but if you are able to work on it, please use #18.