【发布时间】:2013-03-20 15:25:14
【问题描述】:
我正在编写一个简单的客户端和服务器,并想引入一些简单的边界检查以确保用户输入的 IP 地址格式正确,即(int.int.int.int),有没有人有任何建议这可以在我的代码只接受该值的那一刻完成,如果它无效,将引发操作系统错误。但我想阻止用户在这里输入任何内容。
def ipEntered():
global ipEntered
ipEntered = input("Please enter the ip address of the server you wish to connect with:")
谢谢
【问题讨论】:
-
不要忘记允许 hex:hex:hex... 等等 - IOW: 支持 IPv6。与此同时,我们迎来了 2013 年!
标签: python input python-3.x ip-address