Rambert

Change IP

9 posts in this topic

Dear friends i need your help.

I need to change last octect from an IP Address 

 

I have created a _GUICtrlIpAddress_Create where I put my IP Address

After it I can read it but i need to change last octect , i have to add or subtract some units to last octect 

So i have though to make it with 

_GUICtrlIpAddress_GetArray

and others like this but i cant get it

Any idea how can i do it???

 

Thanks 

Share this post


Link to post
Share on other sites



@Rambert Welcome to the forum. How about posting your script so we can see just what you're doing, rather than having us guess ;) Makes it easier for us to help


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hi everybody

 

This my script

 

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>




$Form1 = GUICreate("Calculo IP", 499, 404, 192, 124)
$ButtonOK = GUICtrlCreateButton("Continuar", 96, 344, 75, 33)
GUICtrlSetState(-1, $GUI_FOCUS)
$ButtonSALIR = GUICtrlCreateButton("Salir", 320, 344, 75, 33)
$LabelIPR = GUICtrlCreateLabel("IP ROUTER:", 72, 222, 96, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$IPAddressR = _GUICtrlIpAddress_Create($Form1, 280, 220, 130, 21)
_GUICtrlIpAddress_Set($IPAddressR, "0.0.0.0")
GUISetState(@SW_SHOW)



NEWIP ()
Func NEWIP ()
    Local $aIPROUTER[4] , $aIPNEW[4] , $IPNEW , $IPROUTER
Do
        $nMsg = GUIGetMsg()
        If $nMsg = $ButtonOK Then
            $IPROUTER = _GUICtrlIpAddress_Get($IPAddressR)
            $aIPROUTER = _GUICtrlIpAddress_GetArray($IPROUTER)
                $aIPNEW[0] = $aIPROUTER[0]
                $aIPNEW[1] = $aIPROUTER[1]
                $aIPNEW[2] = $aIPROUTER[2]
                $aIPNEW[3] = $aIPROUTER[3] + 26
                _GUICtrlIpAddress_Set($IPNEW, $aIPNEW[0] & "." & $aIPNEW[1] & "." & $aIPNEW[2] & "." & $aIPNEW[3])
            MsgBox($MB_OK, "Calculo IP ", "Old IP is " & $IPROUTER & " New IP is " & $IPNEW )
        EndIf
Until $nMsg = $ButtonSALIR
EndFunc

 

Share this post


Link to post
Share on other sites

Just make it this way:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Calculo IP", 499, 404, 192, 124)
$ButtonOK = GUICtrlCreateButton("Continuar", 96, 344, 75, 33)
GUICtrlSetState(-1, $GUI_FOCUS)
$ButtonSALIR = GUICtrlCreateButton("Salir", 320, 344, 75, 33)
$LabelIPR = GUICtrlCreateLabel("IP ROUTER:", 72, 222, 96, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$IPAddressR = _GUICtrlIpAddress_Create($Form1, 280, 220, 130, 21)
_GUICtrlIpAddress_Set($IPAddressR, "0.0.0.0")
GUISetState(@SW_SHOW)



NEWIP ()
Func NEWIP ()
    Local $aIPROUTER[4] , $aIPNEW[4] , $IPNEW , $IPROUTER
Do
        $nMsg = GUIGetMsg()
        If $nMsg = $ButtonOK Then
            $IPROUTER = _GUICtrlIpAddress_Get($IPAddressR)
            ConsoleWrite('Old: '&$IPROUTER&@CRLF)
            $aIPROUTER = _GUICtrlIpAddress_GetArray($IPAddressR)        ;must be the handle of IP-Control
                $aIPNEW[0] = $aIPROUTER[0]
                $aIPNEW[1] = $aIPROUTER[1]
                $aIPNEW[2] = $aIPROUTER[2]
                $aIPNEW[3] = $aIPROUTER[3] + 26
                $sNewIP=$aIPNEW[0] & "." & $aIPNEW[1] & "." & $aIPNEW[2] & "." & $aIPNEW[3]
                ConsoleWrite('New: '&$sNewIP&@CRLF)
                _GUICtrlIpAddress_Set($IPAddressR, $sNewIP)
            MsgBox($MB_OK, "Calculo IP ", "Old IP is " & $IPROUTER & " New IP is " & $sNewIP )
        EndIf
Until $nMsg = $ButtonSALIR
EndFunc

 

Share this post


Link to post
Share on other sites

Ok thats OK

Now another questions

And Is possible to get a window into the principal form with messages are being executed with ShellExecuteWait function ???

 

In my case after get new IP i wanna ping that IP 20 times. And would be possible to get that window???

 

 

Dibujo1.JPG

Share this post


Link to post
Share on other sites

a quick draft...

#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>

Global $DOS = Run(@ComSpec & " /K", "", @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) ; run in background an hidden cmd

$hGUI = GUICreate("Command Prompt", 600, 350)
$hEdit = GUICtrlCreateEdit('', 0, 0, 600, 297, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_READONLY))
GUICtrlSetFont(-1, 10, 400, 0, "Lucida Console")
GUICtrlSetBkColor(-1, 0x000000) ; background Black
GUICtrlSetColor(-1, 0x00FF00) ; Text color Green
$ButtonUP = GUICtrlCreateButton("+5", 177, 297, 32, 15)
$ButtonDN = GUICtrlCreateButton("-5", 177, 333, 32, 15)
GUICtrlCreateLabel("IP address:", 5, 313, 70, 20, $SS_CENTERIMAGE)
$IPAddress = _GUICtrlIpAddress_Create($hGUI, 80, 313, 130, 20)
_GUICtrlIpAddress_Set($IPAddress, @IPAddress1)
$ButtonPING = GUICtrlCreateButton("Ping", 215, 297, 150, 50)
$ButtonEXIT = GUICtrlCreateButton("Exit", 370, 297, 150, 50)
$ButtonCLS = GUICtrlCreateButton("CLS", 525, 297, 55, 50)
GUISetState(@SW_SHOW)

While ProcessExists($DOS)
    $idMsg = GUIGetMsg()
    Select
        Case $idMsg = $ButtonEXIT
            Dos("EXIT")
        Case $idMsg = $ButtonPING
            Dos("PING " & _GUICtrlIpAddress_Get($IPAddress))
        Case $idMsg = $ButtonUP
            $aIP = StringSplit(_GUICtrlIpAddress_Get($IPAddress), '.', 2)
            $aIP[3] += 5
            _GUICtrlIpAddress_Set($IPAddress, $aIP[0] & '.' & $aIP[1] & '.' & $aIP[2] & '.' & $aIP[3])
        Case $idMsg = $ButtonDN
            $aIP = StringSplit(_GUICtrlIpAddress_Get($IPAddress), '.', 2)
            $aIP[3] -= 5
            _GUICtrlIpAddress_Set($IPAddress, $aIP[0] & '.' & $aIP[1] & '.' & $aIP[2] & '.' & $aIP[3])
        Case $idMsg = $ButtonCLS
            Dos("CLS")
    EndSelect
WEnd

Func Dos($cmd)
    Local $tail = '' ; clear tail
    Switch $cmd
        Case "exit"
            StdinWrite($DOS, 'Exit' & @CRLF)
            ProcessWaitClose($DOS)
            Return
        Case "cls"
            ; clear screen using cls
            GUICtrlSetData($hEdit, '')
            Return ""
    EndSwitch
    StdinWrite($DOS, $cmd & @CRLF) ; send dos command
    While 1
        $Stdout = StdoutRead($DOS) ; get output from command
        If @extended Then ; if there is output then
            $tail &= $Stdout ; add to tail
            ; read edit ctrl
            $sEdit = GUICtrlRead($hEdit)
            ; limit size in edit to prevent reaching full limit
            If StringLen($sEdit) > 15000 Then
                GUICtrlSetData($hEdit, StringRight($sEdit, 15000)) ; leave only last 15000 chars of "buffer"
            EndIf
            GUICtrlSetData($hEdit, $Stdout, True) ; append stdout to edit ctrl
        ElseIf StringRight($tail, 1) = '>' Then
            Return StringStripWS(StringMid(StringLeft($tail, StringInStr($tail, @CR, 0, -1)), StringInStr($tail, @CR, 0, 1)), 3)
        EndIf
    WEnd
EndFunc   ;==>Dos

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Hi guys.

Those examples are not exactly which i need

But i have got some ideas to try to make it possible

Thanks and regards

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