加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
scan.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
D60 提交于 2016-12-05 18:07 . add source code
# coding=UTF-8
import optparse
import socket
def connScan(tgtHost, tgtPort):
try:
connSkt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connSkt.connect((tgtHost, tgtPort))
connSkt.send('ViolentPython\r\n')
results = connSkt.recv(100)
print('[+]%d/tcp open' % tgtPort)
print('[+]' + str(results))
connSkt.close()
except:
print('[-]%d/tcp close' % tgtPort)
def portScan(tgtHost, tgtPorts):
try:
tgtIp = socket.gethostbyname(tgtHost)
except Exception as e:
print("[-] Cannot resolve '%s' " % tgtHost)
return
try:
tgtName = socket.gethostbyaddr(tgtIp)
print('\n[+] Scan Results for:%s' % tgtName[0])
except:
print('\n[+] Scan Results for:%s' % tgtIp)
socket.setdefaulttimeout(1)
for tgtPort in tgtPorts:
print('Scanning port' + str(tgtPort))
connScan(tgtHost, int(tgtPort))
def main():
parser = optparse.OptionParser('usage%prog -H <target host> -p <target host>')
parser.add_option('-H', dest='tgtHost', type='string', help='specify target host')
parser.add_option('-p', dest = 'tgtPort', type='int', help='specify target port')
options, args = parser.parse_args()
if options.tgtHost is None or options.tgtPort is None:
print(parser.usage)
exit(0)
else:
tgtHost = options.tgtHost
tgtPort = options.tgtPort
args.append(tgtPort)
portScan(tgtHost, args)
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化