import socket,time,thread
import urlparse
import datetime
from libs.Conn_scan import Mongo
from multiprocessing import Process, Queue, Lock, Pool
class PortScan:
def __init__(self, ip, url):
socket.setdefaulttimeout(3)
self.lock = thread.allocate_lock()
self.ip = ip
self.url = url
try:
for i in range(0, 65530):
thread.start_new_thread(self.socket_port, (ip, int(i)))
except:
pass
time.sleep(4)
def socket_port(self,ip, port):
try:
if port >= 65535:
print u'port end'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = s.connect_ex((ip, port))
if result == 0:
self.lock.acquire()
print ip, ':', port, 'open'
self.lock.release()
try:
Mongo.coll['port'].update({"URL":self.url},
{"$push": {'Port' : str(port) }},
upsert = True)
except Exception,e:
print e
s.close()
except:
pass
'''
if __name__ == '__main__':
pool = Pool(processes=10)
with open('10.txt') as f:
for i in f:
i = i.strip('\r').strip('\n')
domain = urlparse.urlparse(i)
if domain.netloc is None:
return None
ip = socket.gethostbyname(domain.netloc)
pool.apply_async(PortScan, (i.strip().strip('\r').strip('\n'),))
print "Started processes"
pool.close()
pool.join()
print "Subprocess done."
'''
#ip = '211.144.100.38'
#print "[...] Start scan port -> IP:",ip
##PortScan(ip)
#print "[...] Stop PortScan"
#if __name__== '__main__':
#IP_list = Mongo.coll['url_ip'].find()
#for i in IP_list:
#print i['IP']
#try:
#if i['IP']:
#PortScan(i['IP'], i['URL'])
#except Exception,e:
#pass
```
python 端口
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- !/usr/bin/python -- coding: utf-8 -- """@version: ??@auth...