hadiasghari / pyasn

Python IP address to Autonomous System Number lookup module. (Supports fast local lookups, and historical lookups using archived BGP dumps.)
Other
294 stars 72 forks source link

fixed socket import error on windows #40

Closed john-a-m closed 7 years ago

john-a-m commented 7 years ago

-added explicit exception to OrderedDict import -wrapped inet_ntop import in try/except

running the command python .\pyasn_util_convert.py --single rib.20161208.2200.bz2 asn_db wouldn't work on Windows. However it does work w/ the change I am proposing. You still won't be able to use the MrtTableDump2 class on Windows, which as far as I can tell is the only thing that uses inet_ntop.

hadiasghari commented 7 years ago

Thank you @john-a-m, I merged this. Is there no equivalent for inet_ntop on Windows?

john-a-m commented 7 years ago

@hadiasghari this repo may be of interest. https://github.com/hickeroar/win_inet_pton/. It's a port of inet_ntop and inet_pton in native python using ctypes. That repo has a very liberal license, so I don't think it would be a problem to do something like.

try:
    from socket import inet_ntop
except ImportError:
    def inet_ntop(address_family, packed_ip):
        #etc
hadiasghari commented 7 years ago

I see, that could indeed be a nice way forward -- if more people are interested in this particular functionality on Windows.