jefhal Posted July 21, 2006 Posted July 21, 2006 This took me a few days (dumb), but I finally found a way to find IP addresses in any text string. It does not validate the IP as being a legitimate address, but it will find ip's hidden within other "junk"... #include <array.au3> Dim $MyString1 $MyString1 = "junk blah blah blah 192.168.1.1 and other junk 32522344 68.3.1.1 my04 22dd---48s9s" $answer = StringRegExp($MyString1,'((?:\d+)(?:\.\d+){3})',3) _ArrayInsert($answer,0,UBound($answer)) _arraydisplay($answer,"$answer") ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
/dev/null Posted July 21, 2006 Posted July 21, 2006 well, it will also detect 1111.2222.3333.4444 as an ip address. Better do this: $answer = StringRegExp($MyString1,'((?:\d{1,3}\.){3}\d{1,3})',3) Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
jefhal Posted July 21, 2006 Author Posted July 21, 2006 $answer = StringRegExp($MyString1,'((?:\d{1,3}\.){3}\d{1,3})',3) Thank you! ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
/dev/null Posted July 21, 2006 Posted July 21, 2006 $answer = StringRegExp($MyString1,'((?:\d{1,3}\.){3}\d{1,3})',3) Thank you! You're welcome. Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
Moderators big_daddy Posted July 21, 2006 Moderators Posted July 21, 2006 well, it will also detect 1111.2222.3333.4444 as an ip address. Better do this: $answer = StringRegExp($MyString1,'((?:\d{1,3}\.){3}\d{1,3})',3) Cheers KurtEven that would see something like "300.200.100.000" as an ip address.
/dev/null Posted July 21, 2006 Posted July 21, 2006 (edited) Even that would see something like "300.200.100.000" as an ip address.well, I never said, that it will only detect a valid IP address You can do that with Regexp as well, however I leave that as an exercise for you guys CheersKurt Edited July 21, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
XxXFaNtA Posted July 21, 2006 Posted July 21, 2006 And another thing: $MyString = "aaaa.bbbb.cccc.dddd.1111.2222.3333.4444.196.128.0.1.300.200.100.000" The result would be also wrong... 4.196.128.0 and 1.300.200.100 /[center][/center]
Moderators big_daddy Posted July 21, 2006 Moderators Posted July 21, 2006 This script by gafrost may be of intrest to you.IP Adress Control
/dev/null Posted July 21, 2006 Posted July 21, 2006 (edited) And another thing:$MyString = "aaaa.bbbb.cccc.dddd.1111.2222.3333.4444.196.128.0.1.300.200.100.000"The result would be also wrong...4.196.128.0and1.300.200.100well, i such a string it would be really hard to detect THE one correct IP address anyway. What's morecorrect?196.128.0.1 or 4.196.128.0 or 128.0.1.3 or 8.0.1.3 or ..... So, where is the criteria to decide whichstring is THE one valid ip address? Hard to define....EDIT: I guess one has to define the delimmiting characters for the IP address, like spaces or tabs, or anything elseto get a correct result.CheersKurt Edited July 21, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
jefhal Posted July 22, 2006 Author Posted July 22, 2006 Even that would see something like "300.200.100.000" as an ip address.While I'd be very interested in seeing the regexp expression that can detect only valid ip addresses, my initial need for this was to parse out ip addresses from the ouput of NSLOOKUP. Since NSLOOKUP only returns valid ip addresses that are in my domain, I really don't need any error checking for my current project. The current code that /dev/null proposed does the job for me. Any takers on the error checking regexp expression? ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
/dev/null Posted July 22, 2006 Posted July 22, 2006 While I'd be very interested in seeing the regexp expression that can detect only valid ip addresses, my initial need for this was to parse out ip addresses from the ouput of NSLOOKUP. Since NSLOOKUP only returns valid ip addresses that are in my domain, I really don't need any error checking for my current project. The current code that /dev/null proposed does the job for me.Ah, I see. For that, your approach would have done the job as well. CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
jefhal Posted July 22, 2006 Author Posted July 22, 2006 (edited) Here's an idea for the error checking version: #include <array.au3> Dim $MyString1 $MyString1 = "junk blah blah blah 192.168.1.1 and other junk 32522344 68.3.1.1 my04 22dd---48s9s 100.2000.2.4 300.22.22.1" $answer1 = StringRegExp($MyString1,'((?:\d+)(?:\.\d+){3})',3) $answer2 = StringRegExp($MyString1,'((?:[1-2]?[0-9]?[0-9]\.){3}(?:[1-2]?[0-9]?[0-9]))',3) _ArrayInsert($answer1,0,UBound($answer1)) _arraydisplay($answer1,"$answer") _ArrayInsert($answer2,0,UBound($answer2)) _arraydisplay($answer2,"$answer") However, it has a problem with the last ip address in the list. It returns 00.22.22.1 even though it should return nothing... Edited July 22, 2006 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
/dev/null Posted July 22, 2006 Posted July 22, 2006 Of course, it's probably always best to make code as portable as possible. I was so happy to have ~anything~ work after so much effort that I stopped there and posted what I had. Maybe a start for the error checking version would be?: [1-2]?[0-9]?[0-9].{3}[1-2]?[0-9]?[0-9] good idea, however, that would also match 290.x.xx, while each part of a valid IP address is restricted to the value 0-255. Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *
jefhal Posted July 23, 2006 Author Posted July 23, 2006 (edited) however, that would also match 290.x.xx, while each part of a valid IP address is restricted to the value 0-255.Well, the following is VERY ugly, but it almost works. I adapted it from something on the web, which permitted answers like 00.42.18.9, but I couldn't get {3} to work, and I could not get rid of the separate octets in the answer array, so I added a loop to delete them:#include <array.au3> Dim $MyString1 $MyString1 = "junk blah blah blah 192.168.1.1 and other junk 32522344 68.3.1.1 my04 22dd---48s9s 100.260.2.4 300.22.22.1" $answer5 = StringRegExp($MyString1,'((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9]))',3) For $i = UBound($answer5) -1 to 0 step - 1 ;MsgBox(0,"mod $i",Mod($i,5) & " : " & $answer5[$i]) if Mod($i,5) <> 4 Then _ArrayDelete($answer5,$i) EndIf Next _ArrayInsert($answer5,0,UBound($answer5)) _arraydisplay($answer5,"$answer5") Any ideas how to do this without the loop? Edited July 23, 2006 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Oviyaa Posted February 10, 2011 Posted February 10, 2011 Why cant you make use of this site http://www.ip-details.com/ for finding ip address . it will fetch the information at a second . it provides information at free cost & good in service ..
Br0k30n3 Posted September 8, 2017 Posted September 8, 2017 Do you have to treat it as an Array. I have been trying to use this example to play around with something. $MyString1 = ClipGet() $answer = StringRegExp($MyString1,"((?:\d{1,3}\.){3}\d{1,3})",3) Send($answer) But $answer ends up being empty. I send ($MyString1) to make sure that it is grabbing what is on the clipboard and it shows the content of the clipboard correctly.
Moderators Melba23 Posted September 8, 2017 Moderators Posted September 8, 2017 (edited) Br0k30n3, StringRegExp when used with option 3 (better known as $STR_REGEXPARRAYGLOBALMATCH) unsurprisingly returns an array, not a single string - so you need to use _ArrayDisplay to see what is in the array and then choose which element you will Send (probably the [0] element if only one match is returned). M23 Edit: Welcome to the AutoIt forums by the way. Edited September 8, 2017 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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