Regex pour trouver l'adresse IP Python
r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
Sriram MK
r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
# Note that '^' at the beginning is optional
r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]{1,2})'
# Python program to validate an Ip address
# re module provides support
# for regular expressions
import re
# Make a regular expression
# for validating an Ip-address
regex = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
# Define a function for
# validate an Ip address
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)