WundaGirl Posted June 14, 2010 Posted June 14, 2010 I need to create a script that does something if the 3rd Octet is between 10 and 20 and does something nothing if 3rd octet is not in that range. Can anyone help? My first challenge is just how to obtain the Computer's IP address.
Moderators Melba23 Posted June 14, 2010 Moderators Posted June 14, 2010 WundaGirl,My first challenge is just how to obtain the Computer's IP addressEver thought of trying the Help file? Under <Macro Reference - System Macros> you will find @IPAddress1 - which gets you what it says on the tin.Then you can use StringSplit on the returned address to separate out the third octet. Remember to convert the resulting string to a number (with Number ) before you check whether it is in the 10-20 range or you will have problems.Give it a go and come back if you have problems 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
GEOSoft Posted June 14, 2010 Posted June 14, 2010 Since I have dedicated today to assisting the needy, here is some code that does what you want. $sVal = StringRegExpReplace(@IPAddress1, "\d+\.\d+\.(\d+).+", "$1") MsgBox(0, "Test", @IpAddress1 & @CRLF & $sVal) Just send the cheque when you get the time. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
niubbone Posted June 14, 2010 Posted June 14, 2010 Also, would like to add a tip for anyone reading this. Before asking in the forum, use everytime (I did and saved me many times instead of coming here asking) the help file Index section typing for any keyword that can lead to the function you are looking for. If you still don't find it, put some function related symbol in front of it. Example: In your case you had to find your ip address. First keywords I would search for in help file would be IP, IPAddress, Find, FindIP. These result wouldn't bring me to what I was looking for. So I would start to adding function symbols in front of it, like (respectively @, _ , # in order of common sense to me) and so on. So put it like this @IP and tadahhhh you found it! You can do this process everytime and after this, if you still can't find anything then ask here. Sometimes happens that functions have odd or multiple shortened names in it and you can't find it by common sense keywords, but it's rare. Other thing is searching by Search. It looks up things by argument. Not as efficent as Index search but helpful sometimes.
WundaGirl Posted June 14, 2010 Author Posted June 14, 2010 My apologies. I am very very new to scripting and autoit. niubbone I heard your suggestions thank you very much.
Moderators Melba23 Posted June 14, 2010 Moderators Posted June 14, 2010 WundaGirl, Ignore our sarcasm - we only do it to tease a little bit. But niubbone's suggestion is a good one - the Help file is your best friend and the answer for simple questions is nearly always there. The problem is that it is so big that the answer can be hard to find at times! Good luck with your coding -0 you know where we are when you run into problems. 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
WundaGirl Posted June 14, 2010 Author Posted June 14, 2010 Oh good Uts too early in my use of this language for me to start pissing people off. I looked at the help files and I dont get "StringRegExpReplace" It is functioning perfectly. But I wanted to use in a select case scenario where I ran this only on specific machines. In order to do that I will need to include values for the first and second octet. $sVal = StringRegExpReplace(@IPAddress1, "\d+\.\d+\.(\d+).+", "$1") MsgBox(0, "Test", @IpAddress1 & @CRLF & $sVal)
Moderators Melba23 Posted June 14, 2010 Moderators Posted June 14, 2010 (edited) I looked at the help files and I dont get "StringRegExpReplace"You and about 99.999999999999999999999999999999999999999999% of the human race! If you are a beginning coder then treat this command as a magic wand which the gurus like GEOSoft hand out from time to time. As I have said before, I have been coding in various languages as a student/hobbyist for over 40 years and SREs are by far the hardest thing I have ever tried to learn - in fact they may be the hardest thing I have ever tried to learn in any subject . (Note the use of "tried to learn" there - I do not claim any great success although I am lot better than I used to be ). As you want to look at all the octets of the IP, I suggest we return to my original suggestion of StringSplit for this - although George will doubtless produce a snazzy SRE in a moment . Here is a code snippet to give you the 4 elements of the IP in an array: $aIPArray = StringSplit(@IPAddress1, ".") MsgBox(0, "My IP", @IPAddress1 & @CRLF & $aIPArray[1] & @CRLF & $aIPArray[2] & @CRLF & $aIPArray[3] & @CRLF & $aIPArray[4]) How are you on arrays? There is a very good tutorial in the Wiki (a link to which is at the top of the page) should you need it. I hope that helps. M23 Edit: typnig. Edited June 14, 2010 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
Thatsgreat2345 Posted June 14, 2010 Posted June 14, 2010 (edited) $sVal = StringRegExpReplace(@IPAddress1, "\d+\.\d+\.(\d+).+", "$1") MsgBox(0, "Test", @IpAddress1 & @CRLF & $sVal)What this does is matches the IP address with an expression which is \d+ so (1 or more numbers) then a . then again 1 or more numbers. Then the parentheses say what you want to do stuff with. In this case since there is only one set of parentheses , the 3rd parameter which the $1 says get whatever the first set of parentheses matches. And in this case it would be the 3rd part of the IP which you are looking to get.Example:192.168.1.101 , would return just the 1.So If $sVal >= 10 Or $sVal <=20 Then ;Execute some code EndifEdit: Melba23 gave you the way to do it if you need all the numbers in the IP address, but still just a small explanation of the code that GEOSoft proposed. Edited June 14, 2010 by Thatsgreat2345
GEOSoft Posted June 14, 2010 Posted June 14, 2010 (edited) $sVal = StringRegExpReplace(@IPAddress1, "\d+\.\d+\.(\d+).+", "$1")All that says is to get the @IPAddress1 then ignore the first digits followed by the dot and the second group of digits followed again by a dot, capture the next group of digits That's the (\d+) part, ignore everything after that starting with the dot. The $1 replaces everything in the expression with the captured group so the return value of $sVal for an @IPAddress1 with a value of 127.128.129.130 will be 129 (3rd group, which is also the captured group).EDIT:Of course I could have really confused it if I wrote it as$sVal = StringRegExpReplace(@IPAddress1, "[\d.]{5,7}\.(\d+).+", "$1")Also it might have failed because I didn't test it that way.@M23, you only get confused because you don't follow the link in my sig. Edited June 14, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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