Jump to content

Change IP


Recommended Posts

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 

Link to comment
Share on other sites

  • Moderators

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

 

Link to comment
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

 

Link to comment
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

Link to comment
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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...