Create Portscan.py
This commit is contained in:
45
Portscan.py
Normal file
45
Portscan.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def scanner(target, port):
|
||||||
|
#Banner Time
|
||||||
|
print("-" * 50)
|
||||||
|
print("Scanning: "+target)
|
||||||
|
print("Port Number: "+port)
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
try:
|
||||||
|
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
socket.setdefaulttimeout(1)
|
||||||
|
result = s.connect_ex((target, port))
|
||||||
|
if result == 0:
|
||||||
|
print("Port {port} is open.")
|
||||||
|
s.close()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Closing Program")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
f=0
|
||||||
|
while f==0:
|
||||||
|
try:
|
||||||
|
if sys.argv == 3:
|
||||||
|
target = socket.gethostbyname(sys.argv[1])
|
||||||
|
port = sys.arg[2]
|
||||||
|
else:
|
||||||
|
print("Error Incorrect Syntax.\n Expected portscan.py <ip> <portnumber>")
|
||||||
|
|
||||||
|
while i != 1:
|
||||||
|
if port not in range(1,65535):
|
||||||
|
port = input("Please enter a valid port:\n")
|
||||||
|
else:
|
||||||
|
i = 1
|
||||||
|
|
||||||
|
scanner(target, port)
|
||||||
|
f=1
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Closing Program")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
except socket.gaierror:
|
||||||
|
target = input("Please enter a valid IP or Hostname:\n")
|
||||||
Reference in New Issue
Block a user