Richard Robertson Posted October 25, 2007 Posted October 25, 2007 (edited) I was writing a program, and figured this might be useful to someone. It is a function that validates a string to see if it contains a valid IP address.Func IsIPAddress($text) Return StringRegExp($text, "(((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))") EndFuncIt returns a 0 (false) if it is not an IP address, and a 1 (true) if it is valid. I know regular expressions confuse people, so I figured I'd share one that I got working. Edited October 25, 2007 by Richard Robertson
Moderators SmOke_N Posted October 25, 2007 Moderators Posted October 25, 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.
Richard Robertson Posted October 25, 2007 Author Posted October 25, 2007 Oh, I didn't know about that. I know mine works though, and it's simple enough for anyone to copy and paste if they want it.
cdtoews Posted March 13, 2008 Posted March 13, 2008 (edited) Thanks, This is useful Edited March 13, 2008 by cdtoews
Jax Posted May 18, 2008 Posted May 18, 2008 (edited) Oh this is awsome! Useful script! Edited May 18, 2008 by Jax
Richard Robertson Posted May 20, 2008 Author Posted May 20, 2008 Interesting thing to dig up. I didn't even realize it had been dug up, I was just randomly checking the scripts.
Xand3r Posted May 20, 2008 Posted May 20, 2008 (edited) the func is ok but it dosen't take in consideration all the facts here is something i did a while ago and it checks for more stuff(everything needed i think ) Func _isip($ip,$P_strict=0) $t_ip=$ip $port=StringInStr($t_ip,":");check for : (for the port) If $port Then ;has a port attached $t_ip=StringLeft($ip,$port-1);remove the port from the rest of the ip If $P_strict Then ;return 0 if port is wrong $zport=Int(StringTrimLeft($ip,$port));retrieve the port If $zport>65000 Or $zport<0 Then Return 0;port is wrong EndIf EndIf $zip=StringSplit($t_ip,".") If $zip[0]<>4 Then Return 0;incorect number of segments If Int($zip[1])>255 Or Int($zip[1])<1 Then Return 0;xxx.ooo.ooo.ooo If Int($zip[2])>255 Or Int($zip[1])<0 Then Return 0;ooo.xxx.ooo.ooo If Int($zip[3])>255 Or Int($zip[3])<0 Then Return 0;ooo.ooo.xxx.ooo If Int($zip[4])>255 Or Int($zip[4])<0 Then Return 0;ooo.ooo.ooo.xxx $bc=1 ; is it 255.255.255.255 ? For $i=1 To 4 If $zip[$i]<>255 Then $bc=0;no ;255.255.255.255 can never be a ip but anything else that ends with .255 can be ;ex:10.10.0.255 can actually be an ip address and not a broadcast address Next If $bc Then Return 0;a broadcast address is not really an ip address... If $zip[4]=0 Then;subnet not ip If $port Then Return 0;subnet with port? Else Return 2;subnet EndIf EndIf Return 1;;string is a ip EndFunc edit:comments Edited May 20, 2008 by TheMadman Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro
tr1px Posted September 24, 2008 Posted September 24, 2008 TheMadman what about ports over 65000? Did you forget those? There are 65535 ports on udp and tcp.
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