Sign in to follow this  
Followers 0
911radio

If and Elseif Wildcards?

8 posts in this topic

I threw together a little gui to allow the user to change IP, DNS etc. between 2 different networks. Just prior to their clicking a button to change the settings, I wanted to give them a little info about the current network (if any) they were on based on the IP address. I want to know if I can change the label based on only a portion of the current IP address that is being returned, hence the wildcards. The following are just the pertinent code snippets, not the code for the whole program. Thanks!

CODE

TCPStartup()

$ip = TCPNameToIP(@ComputerName)

If $ip = "192.168.4.*.*" Then

$netwk = "Office"

ElseIf $ip = "192.168.5.*.*" Then

$netwk = "PS Wireless"

ElseIf $ip = "10.10.2.*.*" Then

$netwk = "Schools"

ElseIf $ip = "169.*.*" Then

$netwk = "Not Connected"

EndIf

$Label1 = GUICtrlCreateLabel("Current Network: " & $netwk, 24, 56, 202, 17)

Share this post


Link to post
Share on other sites



You could do this:

CODE

TCPStartup()

$ip = TCPNameToIP(@ComputerName)

If StringLeft($ip, 10) = "192.168.4." Then

$netwk = "Office"

ElseIf StringLeft($ip, 10) = "192.168.5." Then

$netwk = "PS Wireless"

ElseIf StringLeft($ip, 8) = "10.10.2." Then

$netwk = "Schools"

ElseIf StringLeft($ip, 4) = "169." Then

$netwk = "Not Connected"

EndIf

$Label1 = GUICtrlCreateLabel("Current Network: " & $netwk, 24, 56, 202, 17)


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

I tried that too and when it runs (with my IP of 192.168.5.x) the "Current Network:" shows up blank.

Share this post


Link to post
Share on other sites

Try this:

TCPStartup()
$ip = TCPNameToIP(@ComputerName)
$SPLIT = StringSplit($ip,".")

If IsArray($SPLIT) Then
    If $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "4" Then
        $netwk = "Office"
    ElseIf $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "5" Then
        $netwk = "PS Wireless"
    ElseIf $SPLIT[1] = "10" And $SPLIT[2] = "10" And $SPLIT[3] = "2" Then
        $netwk = "Schools"
    ElseIf $SPLIT[1] = "169"
        $netwk = "Not Connected"
    EndIf
EndIf

$Label1 = GUICtrlCreateLabel("Current Network: " & $netwk, 24, 56, 202, 17)

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Andreik! Worked like a charm!

Edit: One quick question, whats the easiest and most reliable way to refresh the IP and update the status?

Edited by 911radio

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you want without GUI, you can use this to refresh status after 30 sec.

While 1
    $ntwk = GetNetwork()
    TrayTip("Network",$ntwk,5)
    Sleep(30000)
WEnd

Func GetNetwork()
$ip = TCPNameToIP(@ComputerName)
$SPLIT = StringSplit($ip,".")

If IsArray($SPLIT) Then
    If $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "4" Then
        $netwk = "Office"
    ElseIf $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "5" Then
        $netwk = "PS Wireless"
    ElseIf $SPLIT[1] = "10" And $SPLIT[2] = "10" And $SPLIT[3] = "2" Then
        $netwk = "Schools"
    ElseIf $SPLIT[1] = "169"
        $netwk = "Not Connected"
    EndIf
EndIf
Return  $netwk
EndFunc
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Yeah, that took out my GUI completely. Can't have that :P

Share this post


Link to post
Share on other sites

With GUI:

#include <GUIConstants.au3>

#region - GUI Create
GUICreate('Network',100,80)
$BUTTON = GUICtrlCreateButton("CHECK",5,5,90,20)
$LABEL = GUICtrlCreateLabel("",5,30,90,40)
GUISetState()
#endregion

#region - GUI SelectLoop
While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            Exit
        Case $MSG = $BUTTON
            GUICtrlSetData($LABEL,GetNetwork())
    EndSelect
WEnd
#endregion

Func GetNetwork()
$ip = TCPNameToIP(@ComputerName)
$SPLIT = StringSplit($ip,".")

If IsArray($SPLIT) Then
    If $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "4" Then
        $netwk = "Office"
    ElseIf $SPLIT[1] = "192" And $SPLIT[2] = "168" And $SPLIT[3] = "5" Then
        $netwk = "PS Wireless"
    ElseIf $SPLIT[1] = "10" And $SPLIT[2] = "10" And $SPLIT[3] = "2" Then
        $netwk = "Schools"
    ElseIf $SPLIT[1] = "169" Then
        $netwk = "Not Connected"
    EndIf
EndIf
Return  $netwk
EndFunc

When the words fail... music speaks

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0