2017-03-18 2 views
1

Ich habe diesen Port-Scanner für ein Informationssicherheitsprojekt bearbeitet. Der Code funktioniert, aber wirft Fehler (Pycharm Edu) in Zeilen 63 und 34 in dieser Reihenfolge. Die Fehlermeldung für Zeile 63 lautet: 'Zeile 63, in Checkhost (Ziel). Ich habe mir das angeschaut und kann nicht sehen, warum das genau einen Fehler auslösen würde, wie er in Zeile 34 definiert ist. Die Fehlermeldung für Zeile 34 lautet: 'NameError: Globaler Name' conf 'ist nicht definiert'. Es ist nicht klar, warum dies auch ein Problem ist. Jede Hilfe wird sehr geschätzt. Der Python-Code-Umgebung Python ist 2.7.10Python Port Scanner bearbeiten

#! /usr/bin/python 
from logging import getLogger, ERROR # Import Logging Things 
getLogger("scapy.runtime").setLevel(ERROR) # Get Rid if IPv6 Warning 
import scapy 
import sys 
from datetime import datetime # Other stuff 
from time import strftime 

try: 
target = raw_input("[*] Enter Target IP Address: ") 
min_port = raw_input("[*] Enter Minumum Port Number: ") 
max_port = raw_input("[*] Enter Maximum Port Number: ") 
try: 
if int(min_port) >= 0 and int(max_port) >= 0 and 
int(max_port) >= int(min_port): # Test for valid range of ports 
     pass 
    else: # If range didn't raise error, but didn't meet criteria 
     print "\n[!] Invalid Range of Ports" 
     print "[!] Exiting..." 
     sys.exit(1) 
except Exception: # If input range raises an error 
    print "\n[!] Invalid Range of Ports" 
    print "[!] Exiting..." 
    sys.exit(1) 
except KeyboardInterrupt: # In case the user wants to quit 
print "\n[*] User Requested Shutdown..." 
print "[*] Exiting..." 
sys.exit(1) 

ports = range(int(min_port), int(max_port)+1) 
start_clock = datetime.now() # Start clock for scan time 
SYNACK = 0x12 # Set flag values for later reference 
RSTACK = 0x14 

def checkhost(target): # Function to check if target is up 
conf.verb = 0 # Hide output 
try: 
    ping = sr1(IP(dst = ip)/ICMP()) # Ping the target 
    print "\n[*] Target is Up, Beginning Scan..." 
except Exception: # If ping fails 
    print "\n[!] Couldn't Resolve Target" 
    print "[!] Exiting..." 
    sys.exit(1) 

def scanport(port): # Function to scan a given port 
try: 
    srcport = RandShort() # Generate Port Number 
    conf.verb = 0 # Hide output 
    SYNACKpkt = sr1(IP(dst = target)/TCP(sport = srcport, 
dport = port,flags = "S")) 
pktflags = SYNACKpkt.getlayer(TCP).flags 
    if pktflags == SYNACK: # Cross reference Flags 
     return True # If open, return true 
    else: 
     return False 
RSTpkt = IP(dst = target)/TCP(sport = srcport, dport = port, 
flags = "R") # Construct RST packet send(RSTpkt) 
except KeyboardInterrupt: # In case the user needs to quit 
    RSTpkt = IP(dst = target)/TCP(sport = srcport, dport = port, 
flags = "R") send(RSTpkt) 
    print "\n[*] User Requested Shutdown..." 
    print "[*] Exiting..." 
    sys.exit(1) 

checkhost(ip) # Run checkhost() function from earlier 
print "[*] Scanning Started at " + strftime("%H:%M:%S") + "!\n" 

for port in ports: # Iterate through range of ports 
status = scanport(port) # Feed each port into scanning function 
if status == True: # Test result 
    print "Port " + str(port) + ": Open" # Print status 

stop_clock = datetime.now() # Stop clock for scan time 
total_time = stop_clock - start_clock # Calculate scan time 
print "\n[*] Scanning Finished!" # Confirm scan stop 

print "[*] Total Scan Duration: " + str(total_time) # Print scan time 
+2

scheint, als ob Sie ein Modul mit dem Namen "conf" oder ein Modul importieren soll, das diesen Namen enthält .... überprüfen Sie, ob Sie alle Teile mit dieser Importanweisung entfernt haben - nur eine wilde Schätzung – repzero

Antwort

2

Das Problem mit dem Import-Anweisung ist, sollte es sein:

>>> import scapy 
>>> from scapy.all import conf 
>>> conf.verb = 0 

oder noch besser loswerden können ähnliche Fehler in Zukunft nur importieren scapy wie:

>>> from scapy.all import * 
>>> conf.verb = 0 

Jetzt sollte es gut funktionieren.

+0

Danke dafür, es funktioniert jetzt, sehr geschätzt. – screencast

+0

Froh, zu helfen !!! – coder