我是使用python的新手。我将要编写一个简单的telnet程序,但要在适当的地方进行堆栈。在
telnet.py网站
def pingfunc():
global domainname
host = "1.1.1.1"
user = "user1"
password = "password2"
telnet = telnetlib.Telnet(host)
telnet.read_until('Username: ', 3)
telnet.write(user + '\r')
telnet.read_until('Password: ', 3)
telnet.write(password + '\r')
telnet.write("ping " + domainname + "\r\n")
time.sleep(3)
print telnet.read_very_eager()
if __name__ == "__main__":
global domainname
query_string = cgi.parse_qs(os.environ['QUERY_STRING'])
domainname = query_string.get('domainname', ["www.google.com"])[0]
count = query_string.get('count', [COUNT])[0]
当我调用函数(pingfunc)时,出现以下错误:
^{pr2}$你能帮上忙吗?在
在函数
pingfunc()
中使用变量domainname
,而没有在之前声明它(或将其作为参数传递给函数)。在假设调用函数时已经定义了
domainname
,只需更改函数签名即可。在换行:
有:
^{pr2}$当您调用函数时,传递
domainname
作为参数。在相关问题 更多 >
编程相关推荐