gcue Posted June 3, 2008 Share Posted June 3, 2008 im trying to determine the first two quartets for my ip (and seperate each quartet into two vars) i was doing this (which works for ips with two digits in each quartet): $myIP = StringLeft(_GetIP(), 5) $myaIP = StringLeft($myIP, 2) $mybIP = StringRight($myIP, 2) but this wont account for sets that have 3 digits =/ AAA.BBB.CCC.DDD i figure id need something with stringsplit which would use the "." as a delimiter.. but theres multiple "."!!! any ideas? Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 3, 2008 Share Posted June 3, 2008 (edited) You want the first two quartets? Just StringSplit on '.' and read indexes 1 and 2. That's much easier if you ask me. $firsttwoarray = StringSplit("192.168.2.88", ".") $firsttwo = $firsttwoarray[1] & "." & $firsttwoarray[2] Edited June 3, 2008 by Richard Robertson Link to comment Share on other sites More sharing options...
zorphnog Posted June 3, 2008 Share Posted June 3, 2008 And there's always the RegExp way: #include <INet.au3> $aIP = StringRegExp(_GetIP(), "([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)", 3) If Not @error Then _ ConsoleWrite(StringFormat("1:(%03d)\t2:(%03d)\t3:(%03d)\t4:(%03d)\n", $aIP[0], $aIP[1], $aIP[2], $aIP[3])) Link to comment Share on other sites More sharing options...
ProgAndy Posted June 3, 2008 Share Posted June 3, 2008 (edited) ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+) not so good you can give more than 3 digits per quarter \A([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\z is better ( The String must only consist out of the IP, too Edited June 3, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
gcue Posted June 3, 2008 Author Share Posted June 3, 2008 i just did $mIP = StringSplit(_GetIP(), ".") $myIP = $mIP[1] & "." & $mIP[2] forsee any issues? Link to comment Share on other sites More sharing options...
monoceres Posted June 3, 2008 Share Posted June 3, 2008 (edited) Yes, _GetIP() gets the ip from an external website so if the computer is offline there will be no array so $mIP[1] will cause a crash. Rather do: $mIP = StringSplit(_GetIP(), ".") If Not @error Then $myIP = $mIP[1] & "." & $mIP[2] Else $myIP="127.0" EndIf Edit: Fixed code Edited June 3, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
zorphnog Posted June 3, 2008 Share Posted June 3, 2008 ([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+) not so good you can give more than 3 digits per quarter \A([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\z is better ( The String must only consist out of the IP, too Well given that _GetIP() returns a valid IP or -1, I didn't think I needed to be too strict with greediness. Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 3, 2008 Share Posted June 3, 2008 Whoever said that there can be more than 3 digits in a quartet is an idiot. The range per quartet is 0-255 inclusive. 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