我有一个DNS脚本,允许用户通过在Windows命令提示符上键入网站名称来解析DNS名称。
我已经看了几本关于DNS解析的指南,但我的脚本似乎仍然无法将名称(www.google.com)或(google.com)解析为IP地址。
脚本输出错误
Traceback (most recent call last):
File "C:\python\main_menu.py", line 37, in ?
execfile('C:\python\showdns.py')
File "C:\python\showdns.py", line 3, in ?
x = input ("\nPlease enter a domain name that you wish to translate: ")
File "<string>", line 0, in ?
NameError: name 'google' is not defined
代码:
import socket
x = input ("\nPlease enter a domain name that you wish to translate: ")
print ("\n\nThe IP Address of the Domain Name is: "+socket.gethostbyname_ex(x))
x = raw_input("\nSelect enter to proceed back to Main Menu\n")
if x == '1':
execfile('C:\python\main_menu.py')
请对代码给出建议。谢谢!
使用
raw_input
而不是input
。input()是这里使用的错误函数。它实际上计算用户输入的字符串。
而且gethostbyname_ex返回的不仅仅是一个字符串。所以你的打印声明也会失败。
在您的情况下,此代码应该可以工作:
相关问题 更多 >
编程相关推荐