Python????-Nmap???IP??????
???????????? ???????[ 2015/10/22 13:55:18 ] ?????????????????? ?????
	# ??1??????111.206.217.0/24??218.75.110.0/24????????IP???????proxy.nmap_ip???У?type???????????????
	def readIpByAddr():
	ip_list= []
	for i in range(255):
	i = '111.206.217.%s' % i
	j = '218.75.110.%s' % i
	ip_list.append(i)
	ip_list.append(j)
	return ip_list
	def readIpByFile(name):
	frlist = open(name??'r').readlines()
	ip_list = []
	for ip in frlist:
	ip = ip.strip()
	ip_list.append(ip)
	return ip_list
	def insertIP():
	#iplist = readIpByAddr()
	iplist = readIpByFile('iplist.txt');
	conn = db_conn('192.168.88.103'??'root'??'cosmysql'??'proxy')
	cursor = conn.cursor()
	for j in iplist:
	cmdsql = "insert into nmap_ip(ip) values('%s')" % (j)
	print cmdsql
	cursor.execute(cmdsql)
	cursor.close()
	conn.close()
	# ??2???????nmap???????IP????????????????http???????????????????????
	def scan_ip():
	conn = db_conn('192.168.88.103'??'root'??'cosmysql'??'proxy')
	cursor = conn.cursor()
	cursor.execute('select ip from nmap_ip')
	result = cursor.fetchall()                        #???????IP?б?
	for ip in result:
	nmap = "nmap %s | grep 'open'" %ip[0]        #????namp??????
	nmap_result = os.popen(nmap).readlines()    #??貢??????
	if nmap_result == []:                            #Host δ????
	print ip[0]??':NoOpen!'
	else :
	print ip[0]??':Uped??next updateDB'  #format like :['80/tcp  open  http
'?? '443/tcp open  https
']; DB like: ip??http_port??other_port??title??type
	http_port = ''
	other_port =''
	for port_result in nmap_result:            #?????????.??????sql???????.
	port_result = port_result.strip().replace('/tcp'??'').split(' ')
	if port_result[len(port_result)-1] == 'http':
	http_port = port_result[0]
	else:
	other_port = other_port + port_result[0] + '??'
	update_sql = "update nmap_ip set http_port='%s'??other_port='%s' where ip='%s';" % (http_port??other_port??ip[0])
	print update_sql
	update_reslut = cursor.execute(update_sql)
	cursor.close()    #?????.
	conn.close()    #???????.
	# ??3????????????IP??http???????title???????????
	def update_title():
	try:
	conn = db_conn('192.168.88.103'??'root'??'cosmysql'??'proxy')
	cursor = conn.cursor()
	cursor.execute("select IP??http_port from nmap_ip where length(http_port) > 0 ;")
	result = cursor.fetchall()
	pattern = re.compile('<title>(.*?)</title>')
	for ip in result:
	url = 'http://%s:%s' % (ip[0]??ip[1].replace('/tcp'??''))
	print url
	try:
	response = urllib2.urlopen(url)
	html = response.read()
	items = re.findall(pattern??html)
	update_sql = "'update nmap_ip set title='%s' where id='%s' ;" % (items[0][0]??ip)
	print 'update title:'??update_sql
	cursor.execute(update_sql)
	except Exception?? e:
	print e
	pass
	except Exception?? e:
	print e
	pass
	def main4():
	#insertIP()
	#scan_ip()
	update_title()
	if __name__ == '__main__':
	main4()
	????????iplist.txt?????????£?
	101.1.16.123
	101.227.252.130
	101.4.136.34
	101.4.136.66
	101.4.60.43
	101.4.60.46
	101.4.60.47
	101.71.27.120
	103.246.244.161
	103.248.254.172
	103.248.254.173
	103.248.254.174
	103.248.254.175
	103.27.24.113
	103.27.24.114
	103.27.24.114
	106.37.177.251
	110.173.0.58
	110.173.0.58
	110.173.54.154
	110.75.120.170
	111.12.128.167
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com