Giter Site home page Giter Site logo

raphdg / netifaces Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 10.0 120 KB

I'm not the author of netifaces, I just added the project on github and I added a spec file to build the RPM package for the basic Amazon Linux AMI 2012.03

C 72.66% Python 27.34%

netifaces's People

Contributors

raphdg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

netifaces's Issues

IPv6 link-local netmasks appear wrong on Windows 10

Output from netifaces.ifaddresses("enp3s0")[netifaces.AF_INET6]:

[{'addr': 'some link local address here%enp3s0', 'netmask': 'ffff:ffff:ffff:ffff::/64'}]

The netmask for link-local in IPv6 is: 'fe80:0000:0000:0000:0000:0000:0000:0000.' It's specified to be /10 but in practice people use /64. I showed it using the uncompressed form of the address to avoid confusion. The last 64 bits are the host portion.

I'm also not sure the netmask returned for IPv6 'global addresses' makes sense either. With IPv4, you might write something like 0.0.0.0? But netifaces returns FF:FF:... setting all bits to one. It might make more sense to return something like ::/128 -- there is no network part for such global addresses.

Issue with examples on a mac - I incorrectly attached this issue to the Raspberry Pi issue - Please ignore that one

I am getting the following error while using iPython (Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08)) in a terminal window on a mac running Sierra and implementing the following example:

For convenience, we also allow you to index the dictionary with the special value 'default', which returns a dictionary mapping address families to the default gateway in each case. Thus you can get the default IPv4 gateway with

gws = netifaces.gateways()
gws['default'][netifaces.AF_INET]
('10.0.1.1', 'en0')


The results from this test - I tried replacing "[]" with "()" in different combinations but get errors as follows:

In [15]: gws=netifaces.gateways
In [16]: gws['default'][netifaces.AF_INET]

TypeError Traceback (most recent call last)
in ()
----> 1 gws['default'][netifaces.AF_INET]

TypeError: 'builtin_function_or_method' object is not subscriptable

In [17]: gws['default'][netifaces.AF_INET]

TypeError Traceback (most recent call last)
in ()
----> 1 gws['default'][netifaces.AF_INET]

TypeError: 'builtin_function_or_method' object is not subscriptable

In [18]: gws('default')[netifaces.AF_INET]

TypeError Traceback (most recent call last)
in ()
----> 1 gws('default')[netifaces.AF_INET]

TypeError: gateways() takes no arguments (1 given)

In [19]: gws'default'

TypeError Traceback (most recent call last)
in ()
----> 1 gws'default'

TypeError: 'builtin_function_or_method' object is not subscriptable

In [20]: gws('default')(netifaces.AF_INET)

TypeError Traceback (most recent call last)
in ()
----> 1 gws('default')(netifaces.AF_INET)

TypeError: gateways() takes no arguments (1 given)

Is there a solution to this issue?

My alternative to netifaces on Windows

Hello Github,

I've been using netifaces for my P2P networking project and the software is great for the most part. But on Windows it requires the .NET framework which isn't very portable. There is also the issue of interface names being unintelligible and other small bugs. For example: I've noticed on some platforms IPv6 link-local net masks are incorrect. While on Android the software fails to find default gateways. So I've written some patches for these problems.

My own library replaces netifaces on Windows completely with a wrapper around powershell. It uses async coroutines so the program doesn't block. Usage looks like this:

python3 -m asyncio
... REPR starts now with await support ...

from p2pd import *
netifaces = await init_p2pd()

The interface for this object is compatible with netifaces. The software also supports selecting different interfaces for use with network programming and handles loading all address information for you.

i = await Interface()
await i.load_nat()
print(i)

If you're interested in async networking or P2P networking there's more information on p2pd.net. Cheers and hope this issue isn't taken badly.

unintelligible nic names on windows 10?

First, let me say I have no idea whose repo to contribute to for netifaces. The one that pypy lists as the Github project is now 'archived' and no one can contribute to it. I don't know why this was done but I feel it was a bad decision. This project is very useful and multiple people have tried to contribute stuff!

Anyway, NIC names for interfaces on windows are basically just hex strings. The most intelligible data you have for NIC on Windows seems to be the description where you have something like 'Realtek Gaming 2.5GbE Family Controller' instead of '{B2FE597D-E4C7-40E6-960B-E4BFEB88062F}'. I have too much to do to write a pull request but I wanted to provide a simple function that lets you convert a description to a NIC id which can then be used with the netifaces code. Here it is:

def nt_reg_nic(value, desc=0, guid=0):
    import winreg

    nic_keys = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards')
    nic_no, _, _ = winreg.QueryInfoKey(nic_keys)
    for nic_offset in range(0, nic_no):
        nic_key = None
        try:
            nic_key_name = winreg.EnumKey(nic_keys, nic_offset)
            nic_key = winreg.OpenKey(nic_keys, nic_key_name)
            nic_desc, _ = winreg.QueryValueEx(nic_key, "Description")
            nic_guid, _ = winreg.QueryValueEx(nic_key, "ServiceName")

            if desc:
                if value in nic_desc:
                    winreg.CloseKey(nic_keys)
                    return nic_guid 
            if guid:
                if value in nic_guid:
                    winreg.CloseKey(nic_keys)
                    return nic_desc
        except:
            continue
        finally:
            if nic_key is not None:
                winreg.CloseKey(nic_key)

    winreg.CloseKey(nic_keys)
    return None

nt_reg_nic("Realtek Gaming 2.5GbE Family Controller", desc=1) == '{B2FE597D-E4C7-40E6-960B-E4BFEB88062F}'
nt_reg_nic('{B2FE597D-E4C7-40E6-960B-E4BFEB88062F}', guid=1) == "Realtek Gaming 2.5GbE Family Controller"

By the way: to get NIC descriptions for use with this function you can type route print into CMD. This command will show an interface list that has: [nic_no, nic_mac, nic_description] -- the 3rd column is what you can use for the above function. Note also that there's a lot of garbage in this output. I.E. interfaces that might not even have IPs, are virtual interfaces (mine has VBOX interfaces), and so on. As far as I know netifaces also shows all such interfaces on Windows but has some nice functions to show what the 'default' interfaces are for IPv4 and IPv6 routing. So engineers might want to check out that. Cheers.

Using netifaces with Alexa on Amazon Lamda

Give me a moment to get to my question in context.

I am building a skill for Alexa to control my Onkyo Stereo orally. There is already good python code for this project on Github that can be adapted to an Echo skill. The existing code uses netifaces to 'discover' Onkyo receivers on the target network.

I can not get the netifaces module up and running on Amazon Lambda server. The Lambda site does not appear to use .pyd files. No problem, I should not have built netifaces on a Win10 machine and tried to use it on Amazon's Linux server. I built a .so file on my Raspberry Pi 3. Sadly, the PI is 32 bit and the Lambda server is apparently 64 bit since it rejected the 32 bit .so file with an error message to that effect.

Finally the question.

So, can I build a 64 bit .so file with what I have got , a Raspberry Pi and a Win10 machine? If not can some one build me a 64 bit .so file for linux?

Issues when installing on Raspberry Pi

running install
running bdist_egg
running egg_info
writing netifaces.egg-info/PKG-INFO
writing top-level names to netifaces.egg-info/top_level.txt
writing dependency_links to netifaces.egg-info/dependency_links.txt
reading manifest file 'netifaces.egg-info/SOURCES.txt'
writing manifest file 'netifaces.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_ext
checking for getifaddrs... found. (cached)
checking for getnameinfo... found. (cached)
checking for optional header files... netash/ash.h netatalk/at.h netax25/ax25.h neteconet/ec.h netipx/ipx.h netpacket/packet.h linux/irda.h linux/atm.h linux/llc.h linux/tipc.h linux/dn.h. (cached)
checking whether struct sockaddr has a length field... no. (cached)
checking which sockaddr_xxx structs are defined... at ax25 in in6 ipx un ash ec ll atmpvc atmsvc dn irda llc. (cached)
building 'netifaces' extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DNETIFACES_VERSION=0.8 -DHAVE_GETIFADDRS=1 -DHAVE_GETNAMEINFO=1 -DHAVE_NETASH_ASH_H=1 -DHAVE_NETATALK_AT_H=1 -DHAVE_NETAX25_AX25_H=1 -DHAVE_NETECONET_EC_H=1 -DHAVE_NETIPX_IPX_H=1 -DHAVE_NETPACKET_PACKET_H=1 -DHAVE_LINUX_IRDA_H=1 -DHAVE_LINUX_ATM_H=1 -DHAVE_LINUX_LLC_H=1 -DHAVE_LINUX_TIPC_H=1 -DHAVE_LINUX_DN_H=1 -DHAVE_SOCKADDR_AT=1 -DHAVE_SOCKADDR_AX25=1 -DHAVE_SOCKADDR_IN=1 -DHAVE_SOCKADDR_IN6=1 -DHAVE_SOCKADDR_IPX=1 -DHAVE_SOCKADDR_UN=1 -DHAVE_SOCKADDR_ASH=1 -DHAVE_SOCKADDR_EC=1 -DHAVE_SOCKADDR_LL=1 -DHAVE_SOCKADDR_ATMPVC=1 -DHAVE_SOCKADDR_ATMSVC=1 -DHAVE_SOCKADDR_DN=1 -DHAVE_SOCKADDR_IRDA=1 -DHAVE_SOCKADDR_LLC=1 -I/usr/include/python2.7 -c netifaces.c -o build/temp.linux-armv7l-2.7/netifaces.o
netifaces.c:1:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.