911radio Posted October 9, 2008 Share Posted October 9, 2008 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) Link to comment Share on other sites More sharing options...
ken82m Posted October 9, 2008 Share Posted October 9, 2008 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) "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." Link to comment Share on other sites More sharing options...
911radio Posted October 9, 2008 Author Share Posted October 9, 2008 I tried that too and when it runs (with my IP of 192.168.5.x) the "Current Network:" shows up blank. Link to comment Share on other sites More sharing options...
Andreik Posted October 9, 2008 Share Posted October 9, 2008 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. Link to comment Share on other sites More sharing options...
911radio Posted October 9, 2008 Author Share Posted October 9, 2008 (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 October 9, 2008 by 911radio Link to comment Share on other sites More sharing options...
Andreik Posted October 9, 2008 Share Posted October 9, 2008 (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 October 9, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
911radio Posted October 9, 2008 Author Share Posted October 9, 2008 Yeah, that took out my GUI completely. Can't have that Link to comment Share on other sites More sharing options...
Andreik Posted October 9, 2008 Share Posted October 9, 2008 With GUI: expandcollapse popup#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. 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