- Nov 22, 2020
- 4
- 0
- 6
Hi all,
I recently just started taking up Python and Scapy and am facing some difficulties with the script structure.
I was presented with creating a script with these requirements, but I'm unable to make it run so that "-verbose" input changes verbose=0, to verbose=1.
That as well with the output of the list of IP addresses being scanned. Right now, it is only printing out whatever I typed (e.g. 192.168.1.1/24 instead of a list)
This is my current script.
Please help me figure this out as I've been doing my head in for the past 2 weeks trying to create something out of nothing.
I recently just started taking up Python and Scapy and am facing some difficulties with the script structure.
I was presented with creating a script with these requirements, but I'm unable to make it run so that "-verbose" input changes verbose=0, to verbose=1.
That as well with the output of the list of IP addresses being scanned. Right now, it is only printing out whatever I typed (e.g. 192.168.1.1/24 instead of a list)
This is my current script.
Code:
from scapy.all import *
import sys
#If user just run script
if len(sys.argv) == 1:
verbose = 0
user_input=input("Press R to Retry, -v for Verbose, or -help for assistance: ")
if user_input == "R":
destIPs=input("Enter IP Address: ")
pac = IP(dst=destIPs) / ICMP()
ans, unans = sr(pac, timeout=0.5, verbose=0)
ans.summary()
f = open("Network Summary.txt", "w")
print(destIPs, ans, unans, file=f)
f.close()
sys.exit()
elif user_input == "-help":
print("To use this script, enter an IP address or IP range to scan. "
"-verbose brings up the processes of sending/receiving packets")
sys.exit()
elif user_input == "-verbose":
verbose = 1
if verbose == 1:
print("Showing processes...")
destIPs = input("Enter IP Address: ")
pac = IP(dst=destIPs) / ICMP()
ans, unans = sr(pac, timeout=0.5, verbose=0)
ans.summary()
f = open("Network Summary.txt", "w")
print(destIPs, ans, unans, file=f)
f.close()
sys.exit()
#If user runs script + IP Address
elif len(sys.argv) == 2:
pac = IP(dst=sys.argv[1]) / ICMP()
ans, unans = sr(pac, timeout=0.5, verbose=0)
ans.summary()
f = open("Network Scan Results.txt", "w")
print(sys.argv[1], ans, unans, file=f)
f.close()
verbose = 0
Please help me figure this out as I've been doing my head in for the past 2 weeks trying to create something out of nothing.