Tripredacus Posted September 21, 2021 Share Posted September 21, 2021 Every now and then I run into this situation where I am looking at a var and then setting another var, and then for whatever reason it sets the wrong var. I'm fairly sure I've posted at least one topic like this before and it is also likely that I'm making a dumb mistake. I've tried this three different ways, the wrong way, the right way and another right way but the behaviour is the same each time. The original wrong way: $dGateway1 = FileReadLine ( $oDgdat , 2 ) ; read dg from file $dGateway2 = StringRegExpReplace($dGateway1 , "[{"& Chr(34) &"}]" , "") If $dGateway2 = "10.x.1.1" OR "10.x.2.1" THEN $ImageServer = "Server1" ElseIf $dGateway2 = "10.x.3.1" OR "10.x.4.1" THEN $ImageServer = "Server2" ElseIf $dGateway2 = "10.x.5.1" OR "10.x.6.1" THEN $ImageServer = "Server3" EndIf Recreation should be simple enough. I have verified that the data in $dGateway2 is valid via MsgBox and this is working as expected. Could easily just hardcode $dGateway2 to something. I don't think the fact I am reading it from a text file makes a difference. Now in this "wrong" method, what happens is that when on the 1.1 or 2.1 network, $ImageServer var = Server1, as expected. This led me to skip past this and do the rest of the script. After thinking it was working properly, I didn't notice that it wasn't until I tried on the 4.1 network. In that case, $ImageServer also was Server1 when it shouldn't. Remembering that this is the inappropriate use of OR in the If statement, I made it (seemingly) foolproof: If $dGateway2 = "10.x.1.1" THEN $ImageServer = "Server1" ElseIf $dGateway2 = "10.x.2.1" THEN $ImageServer = "Server1" ElseIf $dGateway2 = "10.x.3.1" THEN $ImageServer = "Server2" ElseIf $dGateway2 = "10.x.4.1" THEN $ImageServer = "Server2" ElseIf $dGateway2 = "10.x.5.1" THEN $ImageServer = "Server3" ElseIf $dGateway2 = "10.x.6.1" THEN $ImageServer = "Server3" EndIf And still the same. The 4.1 network was putting Server1 as the var for $ImageServer. So then I tried something else: Select Case StringStripWS($dGateway2 = "10.x.1.1",8) $ImageServer = "Server1" Case StringStripWS($dGateway2 = "10.x.2.1",8) $ImageServer = "Server1" Case StringStripWS($dGateway2 = "10.x.3.1",8) $ImageServer = "Server2" Case StringStripWS($dGateway2 = "10.x.4.1",8) $ImageServer = "Server2" Case StringStripWS($dGateway2 = "10.x.5.1",8) $ImageServer = "Server3" Case StringStripWS($dGateway2 = "10.x.6.1",8) $ImageServer = "Server3" Case Else MsgBox (0,"Error","Gateway is: " & StringStripWS($dGateway2,8) & ". ImageServer is: " & $ImageServer & ".") EndSelect It does match to a case and doesn't fail over to the MsgBox. It seems no matter which value is in $dGateway2 it is setting $ImageServer var to Server1. All of the vars are declared as global prior to their use. Code is being run in 64bit compiled .exe. Hopefully someone can point out my error. Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Nine Posted September 21, 2021 Share Posted September 21, 2021 #1 should be : If $dGateway2 = "10.x.1.1" OR $dGateway2 = "10.x.2.1" THEN $ImageServer = "Server1" ElseIf.... #2 should work #3 should be : Select Case StringStripWS($dGateway2, 8) = "10.x.1.1" $ImageServer = "Server1" Case.... Tripredacus 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2021 Developers Share Posted September 21, 2021 .... and that is assuming there really is an .x. as second octet! Tripredacus 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Tripredacus Posted September 21, 2021 Author Share Posted September 21, 2021 so far so good. 2 hours ago, Jos said: .... and that is assuming there really is an .x. as second octet! Leendert-Jan 1 Twitter | MSFN | VGCollect Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2021 Developers Share Posted September 21, 2021 (edited) Nah ... that is only true for public ranges but doesn't count for the private none routable ranges : Class A : 10.0. 0.0 — 10.255. 255.255. Class B : 172.16. 0.0 — 172.31. 255.255. Class C : 192.168. 0.0 — 192.168. 255.255. Jos Edited September 21, 2021 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Tripredacus Posted September 21, 2021 Author Share Posted September 21, 2021 Sure but it doesn't matter if the IP range is routable or not. Don't discount that people use public support threads for osint. Twitter | MSFN | VGCollect 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