31/03/2011, 18:47
|
المشاركة رقم: 1
|
| المعلومات |
| الكاتب: |
|
| اللقب: |
عضو مميز |
| الصورة الرمزية |
|
|
| البيانات |
| التسجيل : |
May 2010 |
| العضوية : |
134 |
| الاهتمامات : |
Programming .Security |
| الإقامة : |
WAN |
| المواضيع : |
76 |
| الردود : |
522 |
| المجموع : |
598 |
| بمعدل : |
0.10 يوميا |
| الاختراقات : |
[C0Y0T3] |
| مجتمعنا : |
[] |
| الصنف : |
Gray Hat Hacker |
| آخر تواجد : |
17/07/2013/19:28 |
| سبب الغياب : |
الدراسة, العمل, العائلة |
| معدل التقييم: |
16 |
| نقاط التقييم: |
11 |
شكراً: 58
تم شكره 54 مرة في 26 مشاركة
| الإتصالات |
| الحالة: |
|
| وسائل الإتصال: |
|
|
[Python] Port Scanner
كود:
#!/usr/bin/env python
from socket import *
import re
import sys
import getopt
def usage():
print """
PyPortScanner (PPS)
python pscan.py <options>
Options
=======
-a\t--address\t- enter address to scan
-p\t--port\t\t- enter single port to scan
-f\t--from\t\t- start from, scanning range of ports
-t\t--to\t\t- go to, scanning range of ports
-L\t--port_list\t- custom port list
-h\t--help\t\t- print out this help
"""
def get_ts():
from datetime import datetime
ts = datetime.now()
return ts.strftime("%Y-%m-%d %H:%M:%S")
def main(host, ports, verbose):
reg = re.compile(r"""
\b
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
""", re.VERBOSE)
r = reg.match(host)
try:
r.groups()
ip = host
except:
ip = gethostbyname(host)
f = open("log.txt", "w+")
f.write("[%s]\nAnalayzing on host %s\n\n" % (get_ts(),host,))
if verbose:
print "\n==================================="
print " Analayzing %s " % host
print "---------------------------------------------\n"
for port in ports:
s = socket(AF_INET, SOCK_STREAM)
if verbose:
print ("Analayzing port %d ....." % (port, )),
r = s.connect_ex((ip, int(port)))
if(r == 0):
if verbose:
print "OPEN"
current = ("Port %6d OPEN\n" % (port, ))
else:
if verbose:
print "CLOSED"
current = ("Port %6d CLOSED\n" % (port, ))
f.write(current)
s.close()
f.close()
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], "hva:p:f:t:L:", ["help", "verbose", "address=", "port=", "from=", "to=", "port_list="])
except getopt.GetoptError, err:
usage()
sys.exit(2)
host = ''
verbose = False
port = 0
from_port = 0
to_port = 0
list = ''
port_list = []
for option, value in opts:
if option in ("-h", "--help"):
usage()
sys.exit()
elif option in ("-a", "--address"):
host = value
elif option in ("-v", "--verbose"):
verbose = True
elif option in ("-L", "--port_list"):
list = value
elif option in ("-p", "--port"):
port = int(value)
elif option in ("-f", "--from"):
from_port = int(value)
elif option in ("-t", "--to"):
to_port = int(value)
else:
assert False, "Unhandled option"
usage()
sys.exit()
# here i am just making some optimization, more ports to scan longer time to take
# this is only if someone think that he/she is smart and fill all possible options
if (from_port > 0) and (to_port > 0):
if from_port < to_port:
for p in range(int(from_port), int(to_port)):
port_list.append(p)
else:
print "\nFinal port number (-t; --to_port) cannot be grater then start port (-f;--from_port)\n"
usage()
sys.exit()
if list != '':
del port_list[:]
for p in list.split(","):
port_list.append(int(p))
if port != 0:
del port_list[:]
port_list.append(port)
# finaly run the program
main(host, port_list, verbose)
| توقيع : illuminat |
أَنا لاعب النَرْدِ ، أَربح حيناً وأَخسر حيناً.أَنا مثلكمْ أَو أَقلُّ قليلاً ...
|
|
|
|