Sign in to follow this  
Followers 0
smedley89

IP address validation

6 posts in this topic

I'm creating a script that will apply an IP address, subnet mask, and a gateway when needed. In the script, we have two static settings, one for two different devices, as well as a setting that resets the ipv4 back to DHCP.

We are wanting to also allow the user to input an IP address through the script and apply it. So far, all is working well.

My issue here is with validation. Is there a simple way to make sure that the input is in the xxx.xxx.xxx.xxx format? No commas, no letters, that sort of thing?

Also, can an input mask be applied? Say something like having a box that has ---.---.---.---, with the user simply filling in the spaces, allowing some spaces to be empty to accommodate an IP address such as 23.123.23.1?

Near as I can tell, I have the rest done. I've searched through the forums for validation, and input masks, and am not really finding anything that I can (or know how to) use. Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites



Hi smedley,

have a look at the _GUICtrlIpAddress_Create() funtion.

It gives you a Mask and validation.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

If you want to be able to validate an IP address I started a topic a while back that has a function in it that should do what you're looking for. You can find the thread


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

There is an IP address textbox available in KODA to use in your GUI, then you can check whether the string given are digits or not.

I also attempted to do this but its actually harder to accomplish than i thought.

The first digit and last digit may not be 0 as the other middle 0 are allowed to be 0. Also 127.0.0.x may not be given as it is localhost.

To apply a (subnet) mask i did the following;

$arraySubnet = stringsplit($wildcard, ".")
$arrayIP = stringsplit($dstIP, ".")

if $arrayIP[0] <> 4 OR $arraySubnet[0] <> 4 then

  msgbox(16, "Error", "Invalid IPrange.")
else
  for $x = 0 to $arraySubnet[3]
    for $i = 0 to $arraySubnet[4] 
      $dstIP = $arrayIP[1] & "." & $arrayIP[2] & "." & $arrayIP[3] & "." & $arrayIP[4] + $i 
      GUICtrlCreateListViewItem($dstIP, $LVDST)
      ;~  msgbox(1,"", $srcIP)
    Next
    $arrayIP[3] += 1
  Next
EndIf

This works fine because my script reads from a database and the user is not allowed to edit the data... its just an example for subnetting, maybe its useful to you.

Share this post


Link to post
Share on other sites

If you want to be able to validate an IP address I started a topic a while back that has a function in it that should do what you're looking for. You can find the thread

nice!

Share this post


Link to post
Share on other sites

You guys are awesome! Thanks!

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  
Followers 0