我一直在尝试运行这个小端口扫描程序,但我仍然不知道为什么它会给我这个错误:[编辑:我将 IP 字符串重命名为 IPadd,因为它可能混淆了两个编辑现在它说这个错误]
File "thing.py", line 63, in portScan
if (str(type(fin_scan_resp))=="<type 'NoneType'>"):
TypeError: 'int' object is not callable
这是代码:
#!/usr/bin/python
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
from socket import *
import urllib2
import sys
def portScan(target):
validate = 0
print("Simple Port Scanner v1.0")
print("Available port scans")
print("[1] TCP Connect")
print("[2] SYN")
print("[3] ACK")
print("[4] FIN")
#print("[5] XMAS")
print("\n COMMON PORTS: 20, 21, 23, 80")
getport = raw_input("What port will you scan?: ")
port = int(getport)
while validate != 1:
type = input("What kind of scan do you want to do?: ")
print "Selected", type
validate = 1
try:
IPadd = gethostbyname(target)
print(IP) #trace
except:
print("ERROR: Cannot resolve connection... Exiting program")
if type == 1:
tcpconn = socket(AF_INET, SOCK_STREAM)
tcpconn.settimeout(0.255)
#for port in range(20, 25):
isopen = tcpconn.connect_ex((IPadd, port))
if isopen == 0:
print ("TCP Connect: Port " + getport + " is Open")
else:
print ("TCP Connect: Port " + getport + " is Closed")
tcpconn.close()
elif type == 2:
print ("SYN")
synconn = socket(AF_INET, SOCK_STREAM)
synconn.settimeout(0.255)
elif type == 3:
print ("ACK")
elif type == 4:
dst_ip = IPadd
src_port = RandShort()
dst_port= port
fin_scan_resp = sr1(IP(dst=dst_ip)/TCP(dport=dst_port,flags="F"),timeout=10)
if (str(type(fin_scan_resp))=="<type 'NoneType'>"):
print "Open|Filtered"
elif(fin_scan_resp.haslayer(TCP)):
if(fin_scan_resp.getlayer(TCP).flags == 0x14):
print "Closed"
elif(fin_scan_resp.haslayer(ICMP)):
if(int(fin_scan_resp.getlayer(ICMP).type)==3 and int(fin_scan_resp.getlayer(ICMP).code) in [1,2,3,9,10,13]):
print "Filtered"
print ("FIN")
else:
print("Invalid input")
validate = 0
def getTarget():
target = raw_input("Enter target Host name/IP Address: ")
'''
#Validation of ip address still not working
#chk = socket(AF_INET, SOCK_STREAM)
try:
socket.inet_aton(target)
except socket.error:
print("IP address is invalid. QUITTING")
chk.close()
'''
return target
def main():
validate = 0
print("Launch which scan?")
print("[1] Simple Port Scanner v1.0")
print("[2] Service Fingerprinting v1.0")
print("[3] OS Fingerprinting v1.0")
print("[x] Exit")
while validate != 1:
firstMenu = raw_input("Choice: ")
if firstMenu == "1":
print("\n")
validate = 1
name = getTarget()
portScan(name)
elif firstMenu == "2":
print("yep")
validate = 1
elif firstMenu == "3":
print("this")
validate = 1
elif firstMenu == "x":
print("Closing...")
validate = 1
else:
print("Invalid choice")
main()
当我在另一个 .py 文件上运行该部分时,应该有一些错误的部分运行良好,所以我不明白是什么原因造成的,这令人沮丧