扫描工具
Posted xiaohonmao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了扫描工具相关的知识,希望对你有一定的参考价值。
代码如下:
import optparse
import socket
def connScan(tgtHost,tgtPort):
try:
s = socket.socket()
s.connect((tgtHost,int(tgtPort)))
resv = s.recv(1024)
print(‘[+] %s/tcp open‘%tgtPort)
print(‘[+]‘ +str(resv.decode(‘utf-8‘)))
s.close()
except:
#print(tgtHost + ‘ ‘,tgtPort)
print(‘[-] %s/tcp closed‘%tgtPort)
def postScan(tgtHost,tgtPorts):
try:
tgtIP = socket.gethostbyname(tgtHost)
except:
print("[-] Cannot resolve ‘%s‘:Unknown host"%tgtHost)
return
try:
tgtName = socket.gethostbyaddr(tgtIP)
print(‘ [+] Scan Results for:‘+tgtName[0])
except:
print(‘ [+] Scan Results for:‘+tgtIP)
socket.setdefaulttimeout(1)
posts_list = tgtPorts.split(‘,‘)
print(posts_list)
for tgtPort in posts_list:
#print(tgtPort)
print(‘scanning port‘ + tgtPort)
connScan(tgtHost,int(tgtPort))
def main():
parser = optparse.OptionParser()
parser.add_option(‘-H‘,dest="tgtHost",type="string",help="specify target port[s] separated by comma0")
parser.add_option("-P",dest=‘tgtPort‘,type=(‘string‘),help=‘specify target post[s] separated by comma‘)
(options,args)=parser.parse_args()
tgHost = options.tgtHost
tgPorts = options.tgtPort
if (tgHost==None) | (tgPorts==None):
print(‘[-] You must specify a target hos t and port[s].‘)
exit(0)
postScan(tgHost,tgPorts)
if __name__ == ‘__main__‘:
main()
##################################
发这个的原因 买的一本书里面的代码全是2.7的
保存纪念以及方便后续阅读
2018.6.23
##################################
以上是关于扫描工具的主要内容,如果未能解决你的问题,请参考以下文章