Created
October 24, 2020 07:40
-
-
Save ismdeep/8edaaf38534231437671dd114df81a36 to your computer and use it in GitHub Desktop.
判断IP地址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_number(num_str): | |
if len(num_str) <= 0: | |
return False | |
for _item_ in list(num_str): | |
if _item_ not in '0123456789': | |
return False | |
return True | |
def is_ip(s): | |
items = s.split('.') | |
if len(items) != 4: | |
return False | |
for item in items: | |
if not is_number(item): | |
return False | |
if int(item) < 0 or int(item) > 255: | |
return False | |
return True | |
if __name__ == '__main__': | |
print(is_ip('192.168.1.1')) | |
print(is_ip('a.b.c.d')) | |
print(is_ip('1.1.1.2222')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment