Python Scripts
DEMO
portscan.py
import sys, socket
target = sys.argv[1]
minport = int(sys.argv[2])
maxport = int(sys.argv[3])
def porttry(cur_target, port):
try:
s.connect((cur_target, port))
return True
except:
return None
for i in range(minport, maxport+1):
s = socket.socket(2, 1) #socket.AF_INET, socket.SOCK_STREAM
value = porttry(target, i)
if value != None:
print("Port opened on %d" % i)
Run the following command:
sudo python portscan.py 192.168.2.22 20 80
QUICK REVIEW
- Python is another powerful object-oriented language
- Python is a popular language because it's easy to write very powerful programs in just a few lines of code
- Unlike many other languages, Python depends on indentation to define blocks.