0

Kindly comment if there any corrections or improvements

#For IPv6

import re
text='''FE80:CD00:0:0:0:0:211E:729C FE80:CD00:0:CDE:1257:0:211E:729C 
bE80:Cc00:0:0:0:0:211E:727C dFE80:Ca00:0:0:0:0:211E:7295'''  
pattern=re.compile(r'([0-9a-fA-F]{0,4}:){7}[0-9a-fA-F]{0,4}')

matches=pattern.finditer(text)

for match in matches:
    print(match)

For IPv4

import re
ip='''
1.
255.255.222.199 
255.255.222.255 199.244
111.
169.
99.
999.
256.
'''

pattern=re.compile(r'([\d]|[\d]{2}|[1][\d]{2}|[2][0-5]{2})\.([\d]|[\d]{2}|[1][\d]{2}|[2][0-5]{2})\.([\d]|[\d]{2}|[1][\d]{2}|[2][0-5]{2})\.([\d]|[\d]{2}|[1][\d]{2}|[2][0-5]{2})\b')


matches=pattern.finditer(ip)

for match in matches:

    print(match)

Kindly comment if there any corrections or improvements

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chinna
  • 79
  • 7

0 Answers0