簡體   English   中英

Windows上的Scapy-操作系統錯誤?

[英]Scapy on Windows - OS Error?

我在使用python 2.6.3的Windows上運行scapy。

我嘗試運行找到的代碼,但每次都會出現OSError [Errno 9]。

我沒有發現任何Syntex錯誤。

我究竟做錯了什么?

這是源代碼:

from scapy.all import *
import socket
host = raw_input('Host: ')
target = socket.gethostbyname(host)
src = socket.gethostbyname(socket.gethostname())
print "Target IP: ",target
print "Source IP: ",src

srcPort = RandShort()
icmpCodes = [1,2,3,9,10,13]
#startPort = 1
#maxPort = 1024
ports = [21,22,23,25,53,80,110,111,123,143,161,194,443,465,993]
print 'scan is starting...'
for port in ports:
    ans = sr1(IP(dst=target)/TCP(sport=srcPort,dport=port,flags="S"))
    if(str(type(ans))=="<type 'NoneType'>"):
        print "Port %s: Filtered" %(port)
    elif(ans.haslayer(TCP)):
        if(ans.getlayer(TCP).flags == 0x012):#(SYN,ACK)
            send_rst = sr(IP(dst=target)/TCP(sport=srcPort,dport=port,flags="R"))
            print "Port %s: Open" %(port)
        elif (ans.getlayer(TCP).flags == 0x014):#(RST)
            print "Port %s: Closed" %(port)
    elif(ans.haslayer(ICMP)):
        if(int(ans.getlayer(ICMP).type)==3 and int(ans.getlayer(ICMP).code) in     icmpCodes): #Destination Unreachable  
            print "Port %s: Filtered" %(port)

這是我得到的錯誤:

Host: www.google.com
Target IP:  173.194.66.147
Source IP:  192.168.1.8
scan is starting...
Begin emission:
Finished to send 1 packets.
Traceback (most recent call last):
File "D:\Document\Desktop\my_project\TcpSynPortScan_scapy.py", line 16, in <module>
ans = sr1(IP(dst=target)/TCP(sport=srcPort,dport=port,flags="S"))
File "C:\Python26\lib\site-packages\scapy\sendrecv.py", line 335, in sr1
a,b=sndrcv(s,x,*args,**kargs)
File "C:\Python26\lib\site-packages\scapy\arch\windows\__init__.py", line 431, in sndrcv
os.write(1, ".")
OSError: [Errno 9] Bad file descriptor
>>> 

謝謝

我在Linux上嘗試過您的代碼,這似乎很好。

實際上,它嘗試使用不良管道,嘗試使用Logger或Process Monitor進行調試!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM