python3.x 运行脚本报错
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3.x 运行脚本报错相关的知识,希望对你有一定的参考价值。
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from socket import *
import threading
import argparse
lock = threading.Lock()
openNum = 0
threads = []
def portScanner(host,port):
global openNum
try:
s = socket(AF_INET,SOCK_STREAM)
s.connect((host,port))
lock.acquire()
openNum+=1
print('[+] %d open' % port)
lock.release()
s.close()
except:
pass
def main():
p = argparse.ArgumentParser(description='Port scanner!.')
p.add_argument('-H', dest='hosts', type=str)
p.add_argument('-P',dest='port')
args = p.parse_args()
hostList = args.hosts.split(',')
portList = args.port.split(',')
setdefaulttimeout(1)
for host in hostList:
print('Scanning the host:%s......' % (host))
for p in portList:
t = threading.Thread(target=portScanner,args=(host,p))
threads.append(t)
t.start()
for t in threads:
t.join()
print('[*] The host:%s scan is complete!' % (host))
print('[*] A total of %d open port ' % (openNum))
if __name__ == '__main__':
main()
-------------------
运行 python input_test.py -H 127.0.0.1 -P 80,443
报错: TypeError:an integer is required
运行不出错,但没有任何东西,我用的3.x版本
追问try:
s = socket(AF_INET,SOCK_STREAM)
s.connect((host,port))
lock.acquire()
openNum+=1
print('[+] %d open' % port)
lock.release()
s.close()
except:
pass
这个try 去掉就有报错信息了 已经找到了 问题了
以上是关于python3.x 运行脚本报错的主要内容,如果未能解决你的问题,请参考以下文章
python3自动安装脚本,python3.x与python2.x共存
ubuntu将python3设为默认后再安装支持python3.x的包
python3.x运行的坑:AttributeError: 'str' object has no attribute 'decode'