kamene icon indicating copy to clipboard operation
kamene copied to clipboard

subprocess.TimeoutExpired

Open ghost opened this issue 9 years ago • 37 comments

When I run from scapy.all import *, I get the following output:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets     should be working with WinPcap driver and Powershell. Create issues at     https://github.com/phaethon/scapy
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    from scapy.all import *
  File "C:\Python34\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Python34\lib\site-packages\scapy\arch\__init__.py", line 88, in <module>
    from .windows import *
  File "C:\Python34\lib\site-packages\scapy\arch\windows\__init__.py", line 23, in <module>
    from scapy.arch import pcapdnet
  File "C:\Python34\lib\site-packages\scapy\arch\pcapdnet.py", line 32, in <module>
    from .winpcapy import *
  File "C:\Python34\lib\site-packages\scapy\arch\winpcapy.py", line 26, in <module>
    _lib=CDLL('wpcap.dll')
  File "C:\Python34\lib\ctypes\__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

What's wrong?

ghost avatar Dec 13 '15 18:12 ghost

You need WinPcap driver to be installed.

phaethon avatar Dec 28 '15 12:12 phaethon

OK. However, I just installed WinPcap and tried running this:

import scapy.all

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      print("ARP Probe from: " + pkt[ARP].hwsrc)

print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=10))

and I got this error:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
Traceback (most recent call last):
  File "C:\Python34\find_macaddress.py", line 8, in <module>
    print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=10))
  File "C:\Python34\scapy\arch\windows\__init__.py", line 448, in sniff
    s = L2socket(type=ETH_P_ALL, *arg, **karg)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 266, in __init__
    self.ins = open_pcap(iface, 1600, self.promisc, 100)
  File "C:\Python34\scapy\arch\windows\__init__.py", line 224, in <lambda>
    pcapdnet.open_pcap = lambda iface,*args,**kargs:  _orig_open_pcap(pcap_name(iface),*args,**kargs)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 251, in <lambda>
    open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
  File "C:\Python34\scapy\arch\pcapdnet.py", line 215, in __init__
    self.iface = create_string_buffer(device.encode('ascii'))
AttributeError: 'NoneType' object has no attribute 'encode'

ghost avatar Dec 28 '15 18:12 ghost

This is a different error situation. Which version of Windows do you use? It should be working with Windows 8 and above, but Windows 7 and below are currently not directly supported for sniffing/crafting.

phaethon avatar Dec 29 '15 11:12 phaethon

I just upgraded to windows 10... let me check....

ghost avatar Dec 29 '15 19:12 ghost

Huh? First try, this is what I got:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy Traceback (most recent call last): File "C:\Python34\find_macaddress.py", line 1, in import scapy.all File "C:\Python34\scapy\all.py", line 16, in from .arch import * File "C:\Python34\scapy\arch__init__.py", line 88, in from .windows import * File "C:\Python34\scapy\arch\windows__init__.py", line 200, in ifaces.load_from_powershell() File "C:\Python34\scapy\arch\windows__init__.py", line 151, in load_from_powershell for i in get_windows_if_list(): File "C:\Python34\scapy\arch\windows__init__.py", line 79, in get_windows_if_list stdout, stdin = ps.communicate(timeout = 10) File "C:\Python34\lib\subprocess.py", line 960, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "C:\Python34\lib\subprocess.py", line 1216, in _communicate raise TimeoutExpired(self.args, orig_timeout) subprocess.TimeoutExpired: Command '['powershell', 'Get-NetAdapter', '|', 'select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress', '|', 'fl']' timed out after 10 seconds

I'm running it again.

ghost avatar Dec 29 '15 19:12 ghost

Same error!

ghost avatar Dec 29 '15 19:12 ghost

Can you open powershell and execute the command from there? Get-NetAdapter | select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress | fl

phaethon avatar Dec 30 '15 07:12 phaethon

Actually, I reimported scapy.all, I got something saying I can't import scapy.arch.pcapdnet:

WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    import scapy.all
  File "C:\Python34\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Python34\scapy\arch\__init__.py", line 88, in <module>
    from .windows import *
  File "C:\Python34\scapy\arch\windows\__init__.py", line 23, in <module>
    from scapy.arch import pcapdnet
ImportError: cannot import name 'pcapdnet'

ghost avatar Dec 30 '15 21:12 ghost

I'm running it in Windows PowerShell... this was the output...

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\******>powershell
Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.

PS C:\Users\******> Get-NetAdapter | select Name, InterfaceIndex, InterfaceDescription, InterfaceGuid, MacAddress | fl


Name                        : Local Area Connection
InterfaceIndex           : 7
InterfaceDescription : Realtek PCIe FE Family Controller
InterfaceGuid            : {3F66385A-8F2B-46F1-8F45-39163AD3C9C4}
MacAddress             : 2C-27-D7-43-3F-03



PS C:\Users\******>

ghost avatar Dec 30 '15 21:12 ghost

Powershell output seems to be fine. You can try with longer timeout. I have no idea why 10 seconds is not enough to get the result from Powershell call from python. Did you make a clean reinstall of python and scapy after upgrade to Windows 10? If you did not change scapy configuration files then getting new import exception could be caused by some upgrade issues.

phaethon avatar Jan 04 '16 09:01 phaethon

I have some idea about timeout: If I try to run scapy from console with administrative rights then PowerShell calls works fine. If I try to run scapy from console without administrative rights then PowerShell calls ask me to press 'Y' to confirm action. If I try to run scapy from IDE (PyCharm) no matter it is running with or without administrative rights then I receive timeout message whithout any confirmation asks.

fedorch avatar Jan 04 '16 12:01 fedorch

In 1) you can use it then, right? 2) this explains timeout. Have not tested scapy without administrative rights, and probably have to add to documentation that it should be executed with admin rights. 3) Apparently, IDE is affecting normal library loading execution environment. Likely PyCharm specific issue, I will not investigate myself.

phaethon avatar Jan 04 '16 12:01 phaethon

In 1) you can use it then, right?

No. PowerShell calls works whithout problems but they don't return corresponding information (Windows 7)

I just suggested why @qlstudio can have a timeout.

fedorch avatar Jan 04 '16 12:01 fedorch

Python's wierd... sniff() doesn't work but from scapy.all import * does. I'm reinstalling Python and Scapy....

ghost avatar Jan 05 '16 00:01 ghost

I reinstalled Python, same error

ghost avatar Jan 05 '16 21:01 ghost

I have an error: WARNING: Windows support for scapy3k is currently in testing. Sniffing/sending/receiving packets should be working with WinPcap driver and Powershell. Create issues at https://github.com/phaethon/scapy WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6 Traceback (most recent call last): File "C:/Users/axel.ch/Desktop/python bluetooth/wifiPrint.py", line 9, in <module> sniff(prn=wifiPrint) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 445, in sniff s = L2socket(type=ETH_P_ALL, *arg, **karg) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 265, in __init__ self.ins = open_pcap(iface, 1600, self.promisc, 100) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 222, in <lambda> pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface),*args,**kargs) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 250, in <lambda> open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs) File "C:\Users\axel.ch\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 214, in __init__ self.iface = create_string_buffer(device.encode('ascii')) AttributeError: 'NoneType' object has no attribute 'encode'

Can you help me, please

stinng avatar Apr 07 '16 13:04 stinng

@stinng is this related to the original issue? If it is not, create new issue or choose another one, which is related. Please, give your OS, OS version, version of libpcap installed, conf.route output.

phaethon avatar Apr 07 '16 14:04 phaethon

I have that issue, too.

ghost avatar Apr 07 '16 19:04 ghost

It is related because this issue happened just after the original issue. Moreover this issue is already at the top of this webpage. I have windows 10. What is libpcap? I don't think that I have libpcap on my computer.

stinng avatar Apr 07 '16 19:04 stinng

http://www.winpcap.org/ has to be installed for scapy to run.

phaethon avatar Apr 08 '16 04:04 phaethon

I have Winpcap 4.1.3 on my computer. This issue happened after the installation of Winpcap.

stinng avatar Apr 08 '16 07:04 stinng

Me too.

ghost avatar Apr 08 '16 19:04 ghost

Check out with latest commit if the issue is fixed. If it is not fixed, please, add Windows version, and output from show_interfaces()

phaethon avatar Apr 11 '16 10:04 phaethon

I've found some references for the "Get-NetAdapter" error stating that the Get-NetAdapter cmdlet is only available on Windows 8+ and Server 2012+. I was receiving this error on a Windows Server 2008 machine, so this would make sense. If this is the case, I'd recommend @phaethon added which versions of Windows are supported in the ReadMe.md for clarification.

jklahn avatar Apr 11 '16 13:04 jklahn

@jklahn scapy3k used to be working only on Windows 8+, but, currently, it works on Windows 7, too. Which specific error are you referring to?

phaethon avatar Apr 11 '16 14:04 phaethon

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import scapy.all
Traceback (most recent call last):
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 25, in <module>
    import networkx as nx
ImportError: No module named 'networkx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import scapy.all
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 28, in <module>
    log_loading.degub("Can't import networkx. Not criticial, but won't be able to draw network graphs.")
AttributeError: 'Logger' object has no attribute 'degub'
>>> 

I'm pretty sure you meant "debug".

ghost avatar Apr 11 '16 14:04 ghost

Sure I meant :)

phaethon avatar Apr 11 '16 14:04 phaethon

I still have this error

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import scapy.all
Traceback (most recent call last):
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 25, in <module>
    import networkx as nx
ImportError: No module named 'networkx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import scapy.all
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\all.py", line 16, in <module>
    from .arch import *
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\__init__.py", line 28, in <module>
    log_loading.degub("Can't import networkx. Not criticial, but won't be able to draw network graphs.")
AttributeError: 'Logger' object has no attribute 'degub'
>>> import scapy.all
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
>>> 
========== RESTART: C:/Users/DARREN/AppData/Local/Programs/Python/Python35-32/arper.py ==========
WARNING: No match between your pcap and windows network interfaces found. You probably won't be able to send packets. Deactivating unneeded interfaces and restarting Scapy might help.Check your winpcap and powershell installation, and access rights.
WARNING: No route found for IPv6 destination :: (no default route?). This affects only IPv6
Traceback (most recent call last):
  File "C:/Users/DARREN/AppData/Local/Programs/Python/Python35-32/arper.py", line 8, in <module>
    print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=30))
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 452, in sniff
    s = L2socket(type=ETH_P_ALL, *arg, **karg)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 266, in __init__
    self.ins = open_pcap(iface, 1600, self.promisc, 100)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\windows\__init__.py", line 226, in <lambda>
    pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface),*args,**kargs)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 251, in <lambda>
    open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
  File "C:\Users\DARREN\AppData\Local\Programs\Python\Python35-32\lib\site-packages\scapy\arch\pcapdnet.py", line 215, in __init__
    self.iface = create_string_buffer(device.encode('ascii'))
AttributeError: 'NoneType' object has no attribute 'encode'
>>> 

ghost avatar Apr 11 '16 14:04 ghost

arper.py

import scapy.all

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      print("ARP Probe from: " + pkt[ARP].hwsrc)

print(scapy.all.sniff(prn=arp_display, filter="arp", store=0, count=30))

call from show_interfaces

>>> show_interfaces()
INDEX  IFACE                                IP               MAC
>>> 

ghost avatar Apr 11 '16 14:04 ghost

Add, please, get_if_list() output, and conf.iface value. I have a Windows 7 machine with freshly installed scapy from git and WinPcap. And it works, so this is not a generic Windows 7 problem, but related to your configuration. You can try reinstalling WinPcap. Did you check "Start winpcap driver at boot" option when you installed WinPcap?

phaethon avatar Apr 11 '16 14:04 phaethon