IPv4 Regular Expression

by Vitaly, Monday, February 15th, 2016

Accurate regular expression to match IPv4 address:

((([0-9])|(1[0-9][0-9]?)|([2-9][0-9])|(2[0-4][0-9])|(25[0-5]))\.){3}(([0-9])|(1[0-9][0-9]?)|([2-9][0-9])|(2[0-4][0-9])|(25[0-5]))

Tags: ,


Resolve External IP

by Vitaly, Wednesday, July 1st, 2015

URL to resolve IPv4 address:

http://ipv4.test-ipv6.com/ip/?callback=_jqjsp&asn=1&testdomain=test-ipv6.com&testname=test_asn4

Response (IPv4):

_jqjsp({"ip":"xxx.xxx.xxx.xxx","type":"ipv4","subtype":"","via":"","asn":"yyyyy","asn_name":"Provider Name,US","asnlist":"yyyyy","padding":""})

Extract IPv4 regular expression:

\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

URL to resolve IPv6 address:

http://ipv6.test-ipv6.com/ip/?callback=_jqjsp&asn=1&testdomain=test-ipv6.com&testname=test_asn6

Response (IPv6):

_jqjsp({"ip":"xxxx:x:xxxx:xxx:xxxx:xxxx:xxxx:xxxx","type":"ipv6","subtype":"Teredo","via":"","padding":""})

Extract IPv6 regular expression:

([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)

Tags: , , ,