|
|
|||||||
Is there a way to perform an if statement according on a certain string in an IP address. (Like Below) I am fairly new to coding so...; IF instr(@ipaddress0) = "172.18.48." AT (21,1) "Connected via VPN, Not mapping office Printers" sleep 2 exit else .... This doesnt work, so surely there is a better way to do this... |
||||||||
|
|
|||||||
Instr() returns either 0 if it doesn't find the string you are looking for or it returns the location within the string... so you might change your code to: if instr(@ipaddress0,"172.18.48.") ... endif |
||||||||
|
|
|||||||
Don't forget the spaces. if instr(@ipaddress0,"172. 18. 48.")... |
||||||||
|
|
|||||||
As Les mentioned, don't forget the spaces returned from @IPADDRESS0 Code: Break On |
||||||||
|
|
|||||||
Quote: So if the address is "172.18.100.100", it would return a 0 What would it return if the address was "172.18.48.12" |
||||||||
|
|
|||||||
1 |
||||||||
|
|
|||||||
Whilst playing around, I have come up with; Code:
Would this work?? |
||||||||
|
|
|||||||
Oh the spaces... Looks like I got it working! |
||||||||
|
|
|||||||
You shouldn't need 2 IF statements. The IF ELSE ENDIF shown above should be able to handle it, you don't even need an ELSE if you're not going to do anything. Just use an IF ENDIF statement. The SLEEP statements also don't look like their really needed. The usage of GOTO is frowned upon. Dimming your variables is also recommended. |
||||||||
|
|
|||||||
Quote: Just for testing Quote: Will see if I can change it... Thanks. Why is this frowned upon? Quote: Have you got an example? |
||||||||
|
|
|||||||
following or tracing flow of GOTO statements is quite difficult. Scope issues are difficult to control. Example of dimming a variable. You have: $address Dimming it would be like this: Dim $address $address = "something" |
||||||||
|
|
|||||||
See also the FAQ Forum for TCP/IP articles and a whole list of TCP/IP-related UDFs. |
||||||||
|
|
|||||||
I'm SURE there is a UDF to clean up the IP address...or even a way to strip spaces from a string elegantly, but I usually do something like this just so I'm comparing apples to apples... $IP = @IPADDRESS0 $IP = Trim(Substr($IP,1,3))+"."+Trim(Substr($IP,5,3))+"."+Trim(Substr($IP,9,3))+"."+Trim(Substr($IP,13,3)) |
||||||||
|
|
|||||||
Code: Break On |