d2038 Posted September 2, 2009 Posted September 2, 2009 Hello, i need a little help, im using this code to get my public ip and make it a variable:#include <Inet.au3> Do $1=_GetIP() Until $1<> MsgBox(0, "", "It works")Lets say that the ip is 142.13.76.245, what i want is to match only the 142.13 part, so when in the script it differs from this range, the msgbox pops up. Hope u can help me. Sorry for bad english.Cheers.
PsaltyDS Posted September 2, 2009 Posted September 2, 2009 Hello, i need a little help, im using this code to get my public ip and make it a variable: #include <Inet.au3> Do $1=_GetIP() Until $1<> MsgBox(0, "", "It works") Lets say that the ip is 142.13.76.245, what i want is to match only the 142.13 part, so when in the script it differs from this range, the msgbox pops up. Hope u can help me. Sorry for bad english. Cheers. Get the location of the second "." with StringInStr(), then use that for StringLeft(): $sIP = "123.45.67.89" $sIPSlash16 = StringLeft($sIP, StringInStr($sIP, ".", 0, 2) - 1) ConsoleWrite("IP address /16 network = " & $sIPSlash16 & @LF) You do it more geeky with StringRegExp(), but I suspect you don't want to go there yet... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Moderators Melba23 Posted September 2, 2009 Moderators Posted September 2, 2009 (edited) d2038,First, welcome to the Autoit forums.I would deal with your problem this way:; 142.13.76.245, what i want is to match only the 142.13 part $nBegin = TimerInit() While 1 $1 = "142.13.76.245" ; You would put GetIP() here ; If match then exit the While...WEnd loop If StringInStr($1, "142.13.") Then ExitLoop ; Check for timeout If TimerDiff($nBegin) > 10000 Then ; This is set for 10 secs - you alter it to what you want MsgBox(0, "", "Timed Out") Exit ; This exits, you might want to do something else EndIf WEnd MsgBox(0, "", "It works")The StringInStr line checks if the IP contains what you want and if so continues with the rest of the script. The Timer* parts check if a timeout period has elapsed (we do not want to do this all night, do we! ) and exits. Try altering the IP number to see the effect.Ask if anything is unclear.M23Edit: Ah, beaten by a rakishly good looking waterfowl . Edited September 2, 2009 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
d2038 Posted September 2, 2009 Author Posted September 2, 2009 Ty both for ur help, problem solved, StringInStr() and StringLeft() were the functions that i needed, these will help me in the future xD, back to testing and finishing my script, cheers.
trancexx Posted September 2, 2009 Posted September 2, 2009 Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run. It's the last line where the bug is introduced. It should be (that last line that is): MsgBox(64, "Title expressing exhilaration", " I match! ") This is crucial. ♡♡♡ . eMyvnE
PsaltyDS Posted September 2, 2009 Posted September 2, 2009 Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run. It's the last line where the bug is introduced. It should be (that last line that is): MsgBox(64, "Title expressing exhilaration", " I match! ") This is crucial. Which is it today -- too much drugs coffee, or too little? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
trancexx Posted September 2, 2009 Posted September 2, 2009 Which is it today -- too much drugs coffee, or too little? May I paraphrase (somebody, something, somewhere) and say: The shit I provided was meant to be a little over the top and therefore mildly humorous, but nobody ever seems to find the same things funny that I do... ♡♡♡ . eMyvnE
AndyG Posted September 2, 2009 Posted September 2, 2009 Melba23 made a terrible mistake. This must be said and corrected. Otherwise God knows what could happen when that code is run. It's the last line where the bug is introduced. It should be (that last line that is): MsgBox(64, "Title expressing exhilaration", " I match! ") This is crucial. The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial
trancexx Posted September 2, 2009 Posted September 2, 2009 The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial So we could write this: $sIP = "142.13.67.89" If StringLeft($sIP, 7) = "142.13." Then MsgBox(64, "Title expressing exhilaration", " AndyG says I match! ") EndIf ♡♡♡ . eMyvnE
Moderators Melba23 Posted September 3, 2009 Moderators Posted September 3, 2009 The mistake is, that stringinstr($i,"142.13.") matches 116.142.13.155. THIS is crucial Just to keep in the spirit of things: MsgBox(64, "Title expressing sorrow", "M23 apologises profusely") M23 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