Jump to content

IPv6 regular expression


 Share

Recommended Posts

Does anyone know how to find IPv6 expression. 

I have Ipv4 but with IPv6 the address is never strait, some times you have 5 ":"  some times you have 7?

Local $aISITIPv4 = StringRegExp("192.168.0.1", "[0-9]{1,3}+\.[0-9]{1,3}+\.[0-9]{1,3}+\.[0-9]{1,3}", 0)

any ideas how to code for below? Lost :sweating:  Point in right direction or tip please. Begging :lol:

2001:4860:4860::8888
2001:4860:4860::8844
2620:0:ccc::2
2620:0:ccd::2
2a02:6b8::feed:0ff
2a02:6b8:0:1::feed:0ff
2001:67c:28a4::
2002:d596:2a92:1:71:53::
2001:470:6c:521::2
2001:470:6d:521::1
2001:1608:10:25::1c04:b12f
2001:1608:10:25::9249:d69b
2001:910:800::12
2001:910:800::40
2606:4700:4700::1111
2606:4700:4700::1001
2610:a1:1018::1
2610:a1:1019::1
2610:a1:1018::5
2610:a1:1019::5
2a00:5a60::ad1:0ff
2a00:5a60::ad2:0ff
2a02:6b8::feed:a11
2a02:6b8:0:1::feed:a11
2a0d:2a00:1::
2a0d:2a00:2::
2a0d:2a00:1::1
2a0d:2a00:2::1
2610:a1:1018::3
2610:a1:1019::3
2610:a1:1018::4
2610:a1:1019::4
2a00:5a60::bad1:0ff
2a00:5a60::bad2:0ff
2a02:6b8::feed:bad
2a02:6b8:0:1::feed:bad
2a0d:2a00:1::2
2a0d:2a00:2::2
2610:a1:1018::2
2610:a1:1019::2

 

Link to comment
Share on other sites

Ok I think I cracked it

Does this look ok or will it fail on some weird Ipv6?

It failed :(

#include <StringConstants.au3>
Local $aISITIPv6a = StringRegExp("2001:1608:10:25::9249:d69b", "[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}", 0)
Local $aISITIPv6b = StringRegExp("2a0d:2a00:1::", "[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}", 0)
Local $aISITIPv4 = StringRegExp("192.168.0.1", "[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}+\:[0-9]{0,4}", 0)
ConsoleWrite("Sting1 = " & $aISITIPv6a & @CRLF)
ConsoleWrite("Sting2 = " & $aISITIPv6b & @CRLF)
ConsoleWrite("Sting3 = " & $aISITIPv4 & @CRLF) ; Should Fail

 

Edited by Dwalfware
Link to comment
Share on other sites

Ok found the solution

https://www.autoitscript.com/forum/topic/144168-validate-ipv6-address/

#include <StringConstants.au3>
Local $aISITIPv6a = StringRegExp("2001:1608:10:25::9249:d69b", "^(?i)([\da-f]{1,4}|::)((:{0,2}[\da-f]{0,4}){0,7})$", 0)
Local $aISITIPv6b = StringRegExp("2a0d:2a00:1::", "^(?i)([\da-f]{1,4}|::)((:{0,2}[\da-f]{0,4}){0,7})$", 0)
Local $aISITIPv4 = StringRegExp("192.168.0.1", "^(?i)([\da-f]{1,4}|::)((:{0,2}[\da-f]{0,4}){0,7})$", 0)
; Dany Sting = ^(?i)([\da-f]{1,4}|::)((:{0,2}[\da-f]{0,4}){0,7})$
ConsoleWrite("Sting1 = " & $aISITIPv6a & @CRLF)
ConsoleWrite("Sting2 = " & $aISITIPv6b & @CRLF)
ConsoleWrite("Sting3 = " & $aISITIPv4 & @CRLF) ; Should Fail

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...