Jump to content
Sign in to follow this  
James

Validate IPV6 Address

Recommended Posts

Quick function for validating IPV6. It's not advanced, but can validate several notations.

; Default example
If _ISIPV6IP('3ffe:1900:4545:3:200:f8ff:fe21:67cf') Then MsgBox(0, '', 'Valid IPV6 address!')
; Leading zeroes
If _ISIPV6IP('2001:db8:85a3:0:0:8a2e:370:7334') Then MsgBox(0, '', 'Valid IPV6 address!')
; Groups of zeroes
If _ISIPV6IP('2001:db8:85a3::8a2e:370:7334') Then MsgBox(0, '', 'Valid IPV6 address!')

Func _ISIPV6IP($Addr)
Return StringRegExp($Addr, "(([\da-f]{0,4}:{0,2}){1,8})")
EndFunc

Share this post


Link to post
Share on other sites

Nice James.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Nice, but it also returns true for an empty string. You need anchors in your regexp and demand atleast one character. After some playing around I got this:

Func _ISIPV6IP($sAddr)
    Return StringRegExp($sAddr, "^(?i)([\da-f]{1,4}|::)((:{0,2}[\da-f]{0,4}){0,7})$")
EndFunc

Also added case-insensitive flag. Passes 332 of the 486 tests in this perl script. Check the mindboggling regular expression patterns in there :wacko:


[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
Share on other sites

Just out of curiosity, how would you have to modify that to show as invalid an address like this 2001:db8:85a3::8a2e::7334, where's there's 2 sets of double colons?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Nice, but it also returns true for an empty string. You need anchors in your regexp and demand atleast one character. After some playing around I got this:

Func _ISIPV6IP($sAddr)
Return StringRegExp($sAddr, "^(?i)([da-f]{1,4}|::)((:{0,2}[da-f]{0,4}){0,7})$")
EndFunc

Also added case-insensitive flag. Passes 332 of the 486 tests in this perl script. Check the mindboggling regular expression patterns in there :wacko:

Nice, I only wrote it quickly for something at work, but yours is much better. For this, I didn't even visit gskinners website ;)

Share this post


Link to post
Share on other sites

Just out of curiosity, how would you have to modify that to show as invalid an address like this 2001:db8:85a3::8a2e::7334, where's there's 2 sets of double colons?

Dunno, the patterns I linked to are pretty complex. I'd do it with StringReplace however:

Func _ISIPV6IP($sAddr)
    StringReplace($sAddr, '::', '_')
    If @extended > 1 Then Return False
    Return StringRegExp($sAddr, "^(?i)([da-f]{1,4}|::)((:{0,2}[da-f]{0,4}){0,7})$")
EndFunc

With this addition it passes 359 of the 486 tests.


[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • By matwachich
      DEPRECATED: see this new UDF
       
    • By v0id
      I am starting out using AutoIt. Here is a simple form with username and password. I want to check if information entered is valid once user clicks a button.
      My problem now is that it only validates once. E.g.: if I type 5 character username, it will complain it is not 7 character (good). But once I correct that mistake and press the button again it will still say the same thing.
      Do I need to have a loop?
       
      #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $main = GUICreate("Test Tool", 600, 600) $hyourlabel = GUICtrlCreateLabel("YOUR CREDENTIALS", 30, 10, 256) GUICtrlSetFont($hyourlabel, Default, 600) Local $adminfrejalabel = GUICtrlCreateLabel("Username:", 8, 38, 64, 17) Global $adminfrejaid = GUICtrlCreateInput("", 80, 38, 110, 17) Local $adminpasswordlabel = GUICtrlCreateLabel("Password:", 8, 62, 64, 17) Global $adminpassword = GUICtrlCreateInput("", 80, 62, 110, 17, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) $userButton_Check = GUICtrlCreateButton("VALIDATE", 32, 480, 85, 25) GUICtrlSetOnEvent($userButton_Check, "startvalidation") GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func startvalidation() ;CHECK VALIDATIONS $adminfrejaid = GUICtrlRead($adminfrejaid) $adminpassword = GUICtrlRead($adminpassword) If StringLen($adminfrejaid) <> '7' Then MsgBox($MB_SYSTEMMODAL, "User ID", "Please enter exactly 7 characters.") ;Exit EndIf If StringLen($adminpassword) < '5' Then MsgBox($MB_SYSTEMMODAL, "Your Password", "Please enter a valid password.") ;Exit EndIf EndFunc Func ExitGui () Exit ; Exit the program EndFunc  
    • By Dwalfware
      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   Point in right direction or tip please. Begging 
      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  
    • By Dwalfware
      HI
      Another head scratched
      Anyone solve how to get the IPV6 from WMI?
      I followed the usual SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID='" & GUICtrlRead($cboAdapters) & "'
      get the index 
      port it to 
      Local $query = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & _GetSelectedNIC(), "WQL", 0x30 )
      All i can see is IPv4 addresses
      My question is is there another place the IPv6 information is hiding? I configured my LAN with IPV6 and my wireless with IPv4 so I can see what shows.
      Thanks in Advance.
      PS. I did try google
       
    • By ahha
      I'm using the excellent _Excel UDF to read a whole spreadsheet into an array I want to operate on.  I can read a specified range without a problem.  What I'd like to do is allow the user in Excel to select a range (contiguous is fine) and be able to read that range so that I know what range to operate on without having the user input the range via a keyboard.  I'm stuck and any hints greatly appreciated.  The code below uses the Helpfile .xls to illustrate where I crash.
      ; #AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Debug.au3> ;for _DebugArrayDisplay $sExcelFullFileName = "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\Extras\_Excel1.xls" ;use Autoit test for example $oExcel = _Excel_Open() ;Create application object and open an Excel workbook $oWorkbook = _Excel_BookOpen($oExcel, $sExcelFullFileName) $aExcelArray = _Excel_RangeRead($oWorkbook, Default) _DebugArrayDisplay($aExcelArray, $aExcelArray) ;let's look at it $aI5K6 = _Excel_RangeRead($oWorkbook, Default,"I5:K6") ;read a rangeI5:K6 and return value _DebugArrayDisplay($aI5K6, $aI5K6) ;let's look at range it ;rather than defining the range explicity I'd like to read the selection in Excel and use it ;need a function like _Excel_SelectionRead ;try hacking Excel.au3 _Excel_RangeRead to see if can create _Excel_SelectionRead looks like .Selection .Value .Text and .Address possible MsgBox($MB_SYSTEMMODAL, "Info", "Select cells in Excel then click OK") ;ACTUALLY get range of the selection and this will suffice for us to use on the $aExcelArray $vRange = $oWorkbook.ActiveSheet.Selection.Address($vRange) ;tried all sorts of permutations and clearly I need help _DebugArrayDisplay($vRange, $vRange) ;let's look at range it ;$vResult = $oExcel.Transpose($vRange.Value) ;_DebugArrayDisplay($vResult, $vResult) ;let's look at range it _Excel_Close($oExcel, False, True) Exit  
×
×
  • Create New...