擅长:python、mysql、java
<p>如果在验证<code>Ipv4</code>时遇到问题,可以在代码中添加以下逻辑。我有一个类似的<code>tkinter</code>程序,需要<em><code>Ipv4</code>验证</em>。这对我有用。在</p>
<pre><code>import re
# Make a regular expression
# for validating an Ip-address
regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)'''
# Define a function for
# validate an Ip addess
def check(Ip):
# pass the regular expression
# and the string in search() method
if(re.search(regex, Ip)):
print("Valid Ip address")
else:
print("Invalid Ip address")
# Driver Code
if __name__ == '__main__' :
# Enter the Ip address
Ip = "192.168.0.1"
# calling run function
check(Ip)
Ip = "110.234.52.124"
check(Ip)
Ip = "366.1.2.2"
check(Ip)
</code></pre>