-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathportScanner.py
44 lines (35 loc) · 1.02 KB
/
portScanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: lnxg33k
# @Date: 2015-02-08 01:47:45
# @Last Modified by: lnxg33k
# @Last Modified time: 2015-02-08 01:48:24
from sys import argv
from functools import partial
from multiprocessing import Pool
from socket import socket, setdefaulttimeout, error, gethostbyname
processes = 200
setdefaulttimeout(.5)
def ping(host, port):
try:
s = socket()
s.connect((host, port))
try:
return (port, s.recv(1024))
except:
return (port, None) # increase the timeout to get more data
except error:
if error.errno == 111: # connection refused
pass
def threadedScan(host):
p = Pool(processes)
pingHost = partial(ping, host)
return filter(bool, p.map(pingHost, range(1, 65536)))
def main():
# host = "127.0.0.1"
host = gethostbyname(argv[1])
print "[+] Scanning {} ...".format(host)
opendPorts = list(threadedScan(host))
print opendPorts
if __name__ == "__main__":
main()