Penetration Test - Using_Scripting_in_Pen_Testing(6)

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

image-20201213182356873

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.
posted @ 2020-12-13 18:27  晨风_Eric  阅读(54)  评论(0编辑  收藏  举报