Jango Posted November 2, 2007 Posted November 2, 2007 (edited) Hi, I ve made extensive search on the forum but i have not found what i'm looking for. I would like to check if a string is a valide IP address can someone help me or give me a link to a post talking about that ? Cu Edit: Sorry i just noticed i posted in the wrong section, can a mod move my topic thank you and sorry again Edited November 2, 2007 by Jango
rambo3889 Posted November 2, 2007 Posted November 2, 2007 I believe this should do it: Func _StringisIpAndValid($zIp) $t_ip = StringSplit($zIp, ".") If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) And $t_ip[1] <= 255 And $t_ip[2] <= 255 And $t_ip[3] <= 255 And $t_ip[4] <= 255 Then Return True Return False EndFunc My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! youre the best in town Fight!
XxXFaNtA Posted November 2, 2007 Posted November 2, 2007 (edited) Maybe you should use RegularExpressions:Tutorial if you need one (even with a tut on how to check for a valid IP Adress)http://www.regular-expressions.info/examples.html Edited November 2, 2007 by XxXFaNtA /[center][/center]
Jango Posted November 2, 2007 Author Posted November 2, 2007 I believe this should do it: Func _StringisIpAndValid($zIp) $t_ip = StringSplit($zIp, ".") If $t_ip[0] = 4 And StringIsDigit($t_ip[1]) And StringIsDigit($t_ip[2]) And StringIsDigit($t_ip[3]) And StringIsDigit($t_ip[4]) And $t_ip[1] <= 255 And $t_ip[2] <= 255 And $t_ip[3] <= 255 And $t_ip[4] <= 255 Then Return True Return False EndFunc Thank you rambo it is exactly what i'm looking for. Do you made it yourself ?
Blue_Drache Posted November 2, 2007 Posted November 2, 2007 (edited) Your funciton has an error in it. Example: if $zIP = -127.0.0.-1 since -127 is, by definition less than 255, the function will still return true. Edited November 2, 2007 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
weaponx Posted November 2, 2007 Posted November 2, 2007 MsgBox(0,"", "Valid (Returns 0): " & _IsValidIP("192.168.0.1")) MsgBox(0,"", "InValid (Retruns 1): " & _IsValidIP("168.0.1")) MsgBox(0,"", "InValid (Retruns 2): " & _IsValidIP("266.168.0.1")) Func _IsValidIP($theIp) $theArray = StringSplit($theIp, ".") If $theArray[0] <> 4 Then Return 1 For $X = 1 to $theArray[0] If $theArray[$X] < 0 OR $theArray[$X] > 255 Then Return 2 Next Return 0 EndFunc
Blue_Drache Posted November 2, 2007 Posted November 2, 2007 "Build a better error-trap and the programmers will beat down your door" Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
weaponx Posted November 2, 2007 Posted November 2, 2007 (edited) MsgBox(0,"", "Valid (Returns 1): " & _IsValidIPv6("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210")) MsgBox(0,"", "InValid (Returns 0): " & _IsValidIPv6("FEDC::7654:3210::BA98:7654:3210")) Func _IsValidIPv6($theIp) $pattern = "^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}" $pattern &= ":([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}" $pattern &= "(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$" $result = StringRegExp($theIp,$pattern) Return $result EndFunc I tried posting this with AutoIt tags but it said I had too many emoticons! I think I just broke the forum. Edited November 2, 2007 by weaponx
Jango Posted November 2, 2007 Author Posted November 2, 2007 Lol well done IP Board does'nt like too mucha emoticons
Blue_Drache Posted November 2, 2007 Posted November 2, 2007 IP.Board hates emos. *LOL* Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
weaponx Posted November 2, 2007 Posted November 2, 2007 IP.Board hates emos. *LOL*Oh...I'm gonna go slit my wrists and flock of seagalls my hair...
Moderators SmOke_N Posted November 2, 2007 Moderators Posted November 2, 2007 http://www.autoitscript.com/forum/index.ph...c=39932&hl= Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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