我收到一个错误,说该函数需要2个参数而且没有给出任何参数。我以为我已经在主函数中使用了getBanner函数2参数。
import socket
def getBanner2(ip, port):
try:
s = socket.socket()
s.connect((ip, port))
banner = s.recv(1024)
return banner
except Exception, e:
print "[!] " + str(e)
getBanner2()
def main():
#ip1 = raw_input('Enter IP > ')
#port = int(raw_input('Enter Port > '))
ip1 = '10.10.0.115'
port = 22
banner1 = getBanner2(ip1, port)
if banner1:
print '[+] ' + ip1 + ': ' + banner1
if __name__ == '__main__':
main()
以下是错误消息......
Traceback (most recent call last):
File "./getBanner2.py", line 33, in <module>
main()
File "./getBanner2.py", line 26, in main
banner1 = getBanner2(ip1, port)
File "./getBanner2.py", line 17, in getBanner2
getBanner2()
TypeError: getBanner2() takes exactly 2 arguments (0 given)
答案 0 :(得分:0)
在getBanner2
函数中,您再次调用getBanner2()
而没有异常块中的参数。
def getBanner2(ip, port):
try:
s = socket.socket()
s.connect((ip, port))
banner = s.recv(1024)
return banner
except Exception, e:
print "[!] " + str(e)
getBanner2(ip, port) # changed
仔细分析追溯,大多数情况下,它足以找出问题所在。