kamene icon indicating copy to clipboard operation
kamene copied to clipboard

TypeError: a bytes-like object is required, not 'NoneType'

Open miguelmota opened this issue 6 years ago • 4 comments

trying to run example

from scapy.all import *
p = IP(dst = 'www.somesite.ex') / TCP(dport = 80) / Raw(b'Some raw bytes')
sr1(p)
$ python example.py
Traceback (most recent call last):
  File "example.py", line 1, in <module>
    from scapy.all import *
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/all.py", line 25, in <module>
    from .route import *
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/route.py", line 163, in <module>
    conf.route=Route()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/route.py", line 22, in __init__
    self.resync()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/route.py", line 31, in resync
    self.routes = read_routes()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/arch/unix.py", line 82, in read_routes
    ifaddr = scapy.arch.get_if_addr(netif)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scapy/arch/__init__.py", line 52, in get_if_addr
    return socket.inet_ntoa(get_if_raw_addr(iff))
TypeError: a bytes-like object is required, not 'NoneType'
$ uname -a
Darwin computer.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

miguelmota avatar Sep 26 '17 22:09 miguelmota

May be experiencing same issue.

Darwin laptop.local 14.5.0 Darwin Kernel Version 14.5.0: Sun Jun  4 21:40:08 PDT 2017; root:xnu-2782.70.3~1/RELEASE_X86_64 x86_64

Python 3.6.3
scapy-python3    0.21

Exception:

[...]
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/pkg_resources/__init__.py", line[10/175]
n resolve                                                                                                              
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Users/DarrenSpruell/devel/external/project/my_project/__init__.py", line 15, in <module>
    from . import api                                                                                                  
  File "/Users/DarrenSpruell/devel/external/project/my_project/api.py", line 11, in <module>
    from . import app, packetgen                           
  File "/Users/DarrenSpruell/devel/external/project/my_project/packetgen.py", line 7, in <module>               from scapy.all import IP, TCP, UDP, send, conf
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/all.py", line 25, in <module>     
    from .route import *     
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/route.py", line 163, in <module>
    conf.route=Route()
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/route.py", line 22, in __init__
    self.resync()
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/route.py", line 31, in resync
    self.routes = read_routes()
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/arch/unix.py", line 82, in read_ro
utes
    ifaddr = scapy.arch.get_if_addr(netif)
  File "/Users/DarrenSpruell/venv.d/project/lib/python3.6/site-packages/scapy/arch/__init__.py", line 52, in get
_if_addr
    return socket.inet_ntoa(get_if_raw_addr(iff))
TypeError: a bytes-like object is required, not 'NoneType'

dspruell avatar Oct 09 '17 08:10 dspruell

Actually, just noticed like mentioned in #22 that my outcome is different when the netifaces module is not installed. The above exception occurred when netifaces was installed in the virtualenv. When netifaces is removed from the virtualenv (and removed from setuptools dependencies of my package) the application initializes without issue. There is however the initial warning when the module is missing, which was the original reason I had netifaces installed and listed as a requirement:

WARNING: Could not load module netifaces: No module named 'netifaces'

dspruell avatar Oct 09 '17 08:10 dspruell

I am experiencing this issue also. There is a WARNING when netifaces is not installed, but when it is installed, I get the NoneType error

Darwin computer.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

johnsaigle avatar Mar 15 '18 17:03 johnsaigle

I'm experiencing the same issue on Mac OS X 17.7.0 with netifaces available in the virtualenv. The loop through interfaces in arch/unix.py works, but the vboxnet interface triggers the error. In my netstat -rn output the interface is called vboxnet, in netifaces.interfaces(), they are called vboxnetX (with a number), so there's a slight mismatch. Setting conf.use_netifaces = False does not seem to fix that.

hslatman avatar Jan 15 '19 20:01 hslatman