anixon Posted June 11, 2008 Share Posted June 11, 2008 This IP address 1.a.1.1, 0.1.1.1, 1.1.1.1., 256,1,1,1 are processed by the following code as not being a valid ip address with the exception of this 1.1.0.1 which is captured as not being valid at Msgbox 1 CODE$IPAddr = "1.1.0.1" $Split = StringSplit($IPAddr, ".") If $Split[0] = 4 Then For $n = 1 To $Split[0] $IP = $Split[$n] If Not number($IP) and $IP <> "" Then MsgBox(0,"1","Not an IP Address " & $IP) ExitLoop EndIf If($IP < 0) Or ($IP > 255) Then MsgBox(0,"2","Not an IP Address") ExitLoop EndIf If ($n = 1) And ($IP = 0) Then MsgBox(0,"3","Not an IP Address") ExitLoop EndIf Next Else MsgBox(0,"4","Not an IP Address") EndIf Help is always appreciated Ant.. Link to comment Share on other sites More sharing options...
goldenix Posted June 11, 2008 Share Posted June 11, 2008 I dont get it, What are you trying to do?let me see if I understand you, You have this String & you want to check if this string Contains any IP Adresses ? In this casse, can you post the Whole string , this piece is only a part of it right?1.a.1.1, 0.1.1.1, 1.1.1.1., 256,1,1,1 My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
anixon Posted June 11, 2008 Author Share Posted June 11, 2008 I dont get it, What are you trying to do? let me see if I understand you, You have this String & you want to check if this string Contains any IP Adresses ? In this casse, can you post the Whole string , this piece is only a part of it right? 1.a.1.1, 0.1.1.1, 1.1.1.1., 256,1,1,1 An IP address can be any 4 groups number from 0 to 255 seperated with a "." with the exception of the first group which can be any number from 1 to 255. So I want to test each of the four groups to make sure that it is a valid number within the IP range so in the case of the first group it would be any number 1 to 255 in the second third and fourth groups it would be any number in any combination 0 to 255. None of the groupings can contain a non numeric alpha value [a-z]. That being the case 0.1.1.1 is not valid but 1.0.0.1 is also there can not be more than 4 groups so .1.1.1.1 is not valid and neither is 1.1.1.1. [because of the extra "."] or 0.1.1.1.1 or 1.1.1.1.0 because of the extra number group. So at both ends of the spectrum 1.0.0.0 to 255.255.255.255 is the valid range. Ant.. Link to comment Share on other sites More sharing options...
Airwolf Posted June 11, 2008 Share Posted June 11, 2008 (edited) $IPAddr = "1.1.0.1" $Split = StringSplit($IPAddr, ".") If $Split[0] = 4 Then For $n = 1 To $Split[0] $IP = $Split[$n] If StringIsInt($IP) <> 1 Then MsgBox(0,"1","Not an IP Address " & $IP) ExitLoop EndIf If($IP < 0) Or ($IP > 255) Then MsgBox(0,"2","Not an IP Address") ExitLoop EndIf If ($n = 1) And ($IP = 0) Then MsgBox(0,"3","Not an IP Address") ExitLoop EndIf Next Else MsgBox(0,"4","Not an IP Address") EndIf Edited June 11, 2008 by Airwolf Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt Link to comment Share on other sites More sharing options...
anixon Posted June 11, 2008 Author Share Posted June 11, 2008 $IPAddr = "1.1.0.1" $Split = StringSplit($IPAddr, ".") If $Split[0] = 4 Then For $n = 1 To $Split[0] $IP = $Split[$n] If StringIsInt($IP) <> 1 Then MsgBox(0,"1","Not an IP Address " & $IP) ExitLoop EndIf If($IP < 0) Or ($IP > 255) Then MsgBox(0,"2","Not an IP Address") ExitLoop EndIf If ($n = 1) And ($IP = 0) Then MsgBox(0,"3","Not an IP Address") ExitLoop EndIf Next Else MsgBox(0,"4","Not an IP Address") EndIf Arrhhh the magic of "StringIsInt" Ant.. Link to comment Share on other sites More sharing options...
anixon Posted June 11, 2008 Author Share Posted June 11, 2008 (edited) This is the version that I settled on: CODE $iniIP = "1.1.1.256" $ScriptDir = "C:\YourDirectory" $DefaultPingID1 = "Router" $DefaultPingIP1 = "192.168.0.1" CheckIPAddr($iniIP,$scriptDir,"PingID1","PingIP1","Value",$DefaultPingID1,$DefaultPingIP1) Func CheckIPAddr($IPAddr,$ScriptDir,$PingID,$PingIP,$Value,$DefaultPingID,$DefaultPingIP) $Flag = 0 $Split = StringSplit($IPAddr, ".") For $n = 1 To $Split[0] $IP = $Split[$n] If $Split[0] <> 4 then $message = "Not [4] Groups of Numbers" $Flag = 1 EndIf If StringIsInt($IP) <> 1 Then $Message = "Not a Number in a Group/s" $Flag = 1 EndIf If($IP < 0) Or ($IP > 255) Then $Message = "2nd, 3rd or 4th Group Not 0-255" $Flag = 1 EndIf If ($n = 1) And ($IP = 0) Then $Message = "1st Group is Not 1-255" $Flag = 1 EndIf If $flag = 1 then exitloop Next If $Flag = 1 Then message("IP Address Error - " & $Message) IniWrite($ScriptDir, $PingID,$Value, $DefaultPingID) IniWrite($ScriptDir, $PingIP,$Value, $DefaultPingIP) EndIf If $flag = 0 Then message("INI File CHECKED OK") EndIf EndFunc Func message($Message) msgbox(64," Error Message",$Message) EndFunc Edited June 11, 2008 by anixon Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 12, 2008 Share Posted June 12, 2008 0.*.*.* is a valid IP address. By standards it's not used, but it is valid. Link to comment Share on other sites More sharing options...
anixon Posted June 12, 2008 Author Share Posted June 12, 2008 0.*.*.* is a valid IP address. By standards it's not used, but it is valid. Thanks for that I was not aware. I guess additional code will clean up the issue that would allow a user to use that combination [0.*.*.*] Of course a coder at their option can increase the number of IP Tests to exclude any combination [valid or otherwise] as not being an address that operates within their specific environment. Ant.. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 12, 2008 Share Posted June 12, 2008 I hope you understood that * is a wildcard. And yes, of course the code should always have the option. I was simply letting you know for completeness. Link to comment Share on other sites More sharing options...
anixon Posted June 12, 2008 Author Share Posted June 12, 2008 I hope you understood that * is a wildcard.And yes, of course the code should always have the option. I was simply letting you know for completeness.Very important information for those reading this forum. "completeness" a very important ingredient to good code practice Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now