Sign in to follow this  
Followers 0
cramaboule

GUI _GUICtrlIpAddress... need help

3 posts in this topic

Hello,

I set this GUI to set my IP address much more easly.

#include <GuiIPAddress.au3>
#include <GuiConstants.au3>
Global $i

$GUI_SET=GuiCreate("Set IP address", 500, 270,-1, -1 )
; --- Group -----
$Group1 = GuiCtrlCreateGroup("LAN", 10, 10, 230, 190)
$Group2 = GuiCtrlCreateGroup("Wi-Fi", 260, 10, 230, 190)
; --- Labals ----
$Label_3 = GuiCtrlCreateLabel("Now is :", 20, 40, 40, 20)
$Label_19 = GuiCtrlCreateLabel("Now is :", 270, 40, 60, 20)
$Label_13 = GuiCtrlCreateLabel("IP", 20, 100, 60, 20)
$Label_14 = GuiCtrlCreateLabel("Subnet", 20, 130, 60, 20)
$Label_15 = GuiCtrlCreateLabel("Gateway", 20, 160, 60, 20)
$Label_23 = GuiCtrlCreateLabel("IP", 270, 100, 60, 20)
$Label_24 = GuiCtrlCreateLabel("Subnet", 270, 130, 70, 20)
$Label_25 = GuiCtrlCreateLabel("Gateway", 270, 160, 60, 20)
; --- Radios ----
$DhcpLan = GuiCtrlCreateRadio("DHCP", 130, 70, 70, 20)
$SetLan  = GuiCtrlCreateRadio("Set manually", 20, 70, 80, 20)
$DhcpWan = GuiCtrlCreateRadio("DHCP", 380, 70, 70, 20)
$SetWan  = GuiCtrlCreateRadio("Set manually", 270, 70, 80, 20)
; --- Actual IP ----
$IpLanIs = _GUICtrlIpAddressCreate ($GUI_SET, 70, 40, 140, 20)
_GUICtrlIpAddressSet ($IpLanIs, @IPAddress1)
$IpWanIs = _GUICtrlIpAddressCreate ($GUI_SET, 320, 40, 140, 20)
_GUICtrlIpAddressSet ($IpWanIs, @IPAddress2)
; --- Settings IP ----
$IpLanSet = _GUICtrlIpAddressCreate ($GUI_SET, 70, 100, 140, 20)
$SubLan   = _GUICtrlIpAddressCreate ($GUI_SET, 70, 130, 140, 20)
$GatLan   = _GUICtrlIpAddressCreate ($GUI_SET, 70, 160, 140, 20)
;
$IpWanSet = _GUICtrlIpAddressCreate ($GUI_SET, 320, 100, 140, 20)
$SubWan   = _GUICtrlIpAddressCreate ($GUI_SET, 320, 130, 140, 20)
$GatWan   = _GUICtrlIpAddressCreate ($GUI_SET, 320, 160, 140, 20)
;
; --- buttons ----
;
$Set_IP = GuiCtrlCreateButton("Set IP", 200, 220, 100, 30)
$Refresh = GuiCtrlCreateButton("Refresh", 50, 220, 100, 30)
$Exit = GuiCtrlCreateButton("Exit", 350, 220, 100, 30)
;

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit Or _IsPressed("1B")
            ExitLoop
        Case $msg = $Refresh
            _Refresh()
        Case GUICtrlRead ($SetLan) = 1 And $Set_IP = $msg
            $IpLanSeti = _GUICtrlIpAddressGet ( $IpLanSet )
            $SubLani = _GUICtrlIpAddressGet ( $SubLan )
            $GatLani = _GUICtrlIpAddressGet ( $GatLan )
            RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& _Lanlang(1) &chr(34)&" static "& $IpLanSeti &" "& $SubLani &" "& $GatLani & " 0", "", @SW_HIDE)
            MsgBox (32, "Done", "Your LAN is now Set !")
            _Refresh()
        Case GUICtrlRead ($DhcpLan) = 1 And $Set_IP = $msg
            RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& _Lanlang(1) &chr(34)&" dhcp", "", @SW_HIDE)
            MsgBox (32, "Done", "Your LAN is now in DHCP !")
            _Refresh()
        Case GUICtrlRead ($SetWan) = 1 And $Set_IP = $msg
            $IpWanSeti = _GUICtrlIpAddressGet ( $IpWanSet )
            $SubWani = _GUICtrlIpAddressGet ( $SubWan )
            $GatWani = _GUICtrlIpAddressGet ( $GatWan )
            RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& _Lanlang(0) &chr(34)&" static "& $IpWanSeti &" "& $SubWani &" "& $GatWani & " 0", "", @SW_HIDE)
            MsgBox (32, "Done", "Your Wi-Fi is now Set !")
            _Refresh()
        Case GUICtrlRead ($DhcpWan) = 1 And $Set_IP = $msg
            RunWait(@ComSpec & " /c netsh interface ip set address "&chr(34)& _Lanlang(0) &chr(34)&" dhcp", "", @SW_HIDE)
            MsgBox (32, "Done", "Your Wi-Fi is now in DHCP !")
            _Refresh()
        Case Not( _GUICtrlIpAddressIsBlank ( $IpWanSet ) )
            If GUICtrlRead($SetWan,$GUI_UNCHECKED) And $i=0 Then
                $i = 1
                GUICtrlSetState ($SetWan,$GUI_CHECKED)
            EndIf
                _GUICtrlIpAddressSet ($SubWan, "255.255.255.0")
                _GUICtrlIpAddressSet ($GatWan, (_GUICtrlIpAddressGet ( $IpWanSet )))
        Case Not( _GUICtrlIpAddressIsBlank ( $IpLanSet ) )
            If GUICtrlRead($SetLan,$GUI_UNCHECKED) And $i=0 Then
                $i = 1
                GUICtrlSetState ($SetLan,$GUI_CHECKED)
            EndIf
                _GUICtrlIpAddressSet ($SubLan, "255.255.255.0")
                _GUICtrlIpAddressSet ($GatLan, (_GUICtrlIpAddressGet ( $IpLanSet )))
        Case Else
        ;;;
    EndSelect
WEnd
Exit

Func _Refresh()
    $i = 0
    GUICtrlSetState ($DhcpLan,$GUI_UNCHECKED)
    GUICtrlSetState ($SetLan,$GUI_UNCHECKED)
    GUICtrlSetState ($DhcpWan,$GUI_UNCHECKED)
    GUICtrlSetState ($SetWan,$GUI_UNCHECKED)
    _GUICtrlIpAddressSet ($IpLanIs, @IPAddress1)
    _GUICtrlIpAddressSet ($IpWanIs, @IPAddress2)
    _GUICtrlIpAddressClear ($IpLanSet)
    _GUICtrlIpAddressClear ($SubLan)
    _GUICtrlIpAddressClear ($GatLan)
    _GUICtrlIpAddressClear ($IpWanSet)
    _GUICtrlIpAddressClear ($SubWan)
    _GUICtrlIpAddressClear ($GatWan)
EndFunc

;MsgBox(0, "Your OS Language:", _Lanlang())

Func _Lanlang($LAN)
Select
    Case StringInStr("0409,0809,0c09,1009,1409,1809,1c09,2009,2409,2809,2c09,3009,3409", @OSLang);english
        If $LAN = 0 Then
            Return "Wireless Network Connection"
        Else
            Return "Local Area Connection"
        EndIf
    Case StringInStr("040c,080c,0c0c,100c,140c,180c", @OSLang); frensh
        If $LAN = 0 Then
            Return "Connexion réseau sans fil"
        Else
            Return "Connexion au réseau local"
        EndIf
    Case Else
        Return "Other (can't determine with @OSLang directly)"
    EndSelect
EndFuncoÝ÷ ÛöÈ*.$êÞm«­¢+Ø
Í9½Ð }U%
Ñɱ%ÁÉÍÍ%Í  ±¹¬ ÀÌØí%Á]¹MФ¤(%U%
ÑɱI ÀÌØíMÑ]¸°ÀÌØíU%}U9
!
-¤¹ÀÌØí¤ôÀQ¡¸(ÀÌØí¤ôÄ(U%
ÑɱMÑMÑÑ ÀÌØíMÑ]¸°ÀÌØíU%}
!
-¤(¹%(}U%
Ñɱ%ÁÉÍÍMÐ ÀÌØíMÕ]¸°ÅÕ½ÐìÈÔÔ¸ÈÔÔ¸ÈÔÔ¸ÀÅÕ½Ðì¤(}U%
Ñɱ%ÁÉÍÍMÐ ÀÌØíÑ]¸°¡}U%
Ñɱ%ÁÉÍÍÐ ÀÌØí%Á]¹MФ¤¤

My gateway gets his address from the Ip address but after I entered the IP, I would like to change the gateway address...

So, how can I do that ?

I try to figure this out but, I can't !

Do we have a "loose focus" function or "an end of edit" function ? tried to search in the Help but ... nothing !

Or how can I copy only some part of the IP address ?

Thanks in advance for your help.

[edit]

I Posted now in the right forum !

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

My gateway gets his address from the Ip address but after I entered the IP, I would like to change the gateway address...

So, how can I do that ?

I'm not sure if this answers your question but here goes.

Add this before your while 1 loop

$storedip = '' ; a record of the last ip value read from the $IpWanSet

then change this case statement

Case   NOT( _GUICtrlIpAddressIsBlank ( $IpWanSet ) )

            If GUICtrlRead($SetWan,$GUI_UNCHECKED) And $i=0 Then
                $i = 1
                GUICtrlSetState ($SetWan,$GUI_CHECKED)
            EndIf
                _GUICtrlIpAddressSet ($SubWan, "255.255.255.0")
                $lastIP = _GUICtrlIpAddressGet ( $IpWanSet )
                If $lastIP <> $storedip Then
                     _GUICtrlIpAddressSet ($GatWan, $lastip)
                    $storedip = $lastip
                 EndIf

This way the $GatWan is only changed to be the same as $IpWanSet if $IpWanSet is changed.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

:) yeeeeeeeeeee

Thanks ! That's what I meant !

I used this "trick" often,... but could not for some reason find a simple solution.

Thank you so much martin !

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