Sign in to follow this  
Followers 0
whiteball

changing netwrok ip address

13 posts in this topic

Hello pls help me i have primitive way of doing it


Send("{lwindown}r{lwinup}")
            WinWaitActive("Run")
            Send("control panel{enter}")
            WinWaitActive("Control Panel")
            Send("network")
            Send("{enter}")
            WinWaitActive("Network Connections")
        ;~ MsgBox(0,"","don")
            Send("local")
            Send("{enter}")
            WinWaitActive("Local Area Connection Status")
            Send("!p")
            WinWaitActive("Local Area Connection Properties")
            Send("internet")
            Send("!r")
            WinWaitActive("Internet Protocol (TCP/IP) Properties")
            Send("!s")
            Send("{tab}")
            Send(GUICtrlRead($TextBoxIP))
            Send("{tab}")
            Send(GUICtrlRead($TextBoxSubnet))
            Send("{tab}")
            Send(GUICtrlRead($TextBoxGateWay))
            Send("{tab}")
            Send("{tab}")
            Send(GUICtrlRead($TextBoxDNSPrim))
            Send("{tab}")
            Send(GUICtrlRead($TextBoxDNSSec))
            Send("{enter}")
            WinWaitActive("Local Area Connection Properties")
            Send("!{F4}")
            WinWaitActive("Local Area Connection Status")
            Send("!c")
;~             MsgBox(64, "Network Setup Complete", "The Network Properties was Changed Successfully", 2)
            WinWaitActive("Network Connections")
            Send("!{F4}")


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                        





(adsbygoogle = window.adsbygoogle || []).push({});




                    
                
                    
                    
                    






    
    
        
Dickb   

    
        
    
             0
    
        
    

        
            
                Adventurer
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                133 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #2 · 
            Posted 
            
            
            
        
    

    


            
        
            
Hello pls help me i have primitive way of doing it
Maybe this piece of code does the trick,
StaticIpAddress("Local Area Network", "192.168.1.10", "255.255.255.0", "192.168.1.1")

Exit

Func StaticIpAddress($szAdapterName, $szIP, $szSubnet, $szGateway, $iMetric = 1)
    Local $strIPAddress[1] = [$szIP]
    Local $strSubnetMask[1] = [$szSubnet]
    Local $strGateway[1] = [$szGateway]
    Local $strGatewayMetric[1] = [$iMetric]
    
    $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
    $colNetAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE AND Description LIKE '" & $szAdapterName & "%'")

    $errGateways = -1
    $errEnable = -1
    For $objNetAdapter in $colNetAdapters
        $errEnable = $objNetAdapter.EnableStatic($strIPAddress, $strSubnetMask)
        $errGateways = $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
    Next

    $objWMIService = 0
    $colNetAdapters = 0
    $objNetAdapter = 0
    Return (Not $errEnable)
EndFunc

Is at least easier than finding out what buttons to click :whistle:

Share this post


Link to post
Share on other sites

Maybe this piece of code does the trick,

StaticIpAddress("Local Area Network", "192.168.1.10", "255.255.255.0", "192.168.1.1")

Exit

Func StaticIpAddress($szAdapterName, $szIP, $szSubnet, $szGateway, $iMetric = 1)
    Local $strIPAddress[1] = [$szIP]
    Local $strSubnetMask[1] = [$szSubnet]
    Local $strGateway[1] = [$szGateway]
    Local $strGatewayMetric[1] = [$iMetric]
    
    $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
    $colNetAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE AND Description LIKE '" & $szAdapterName & "%'")

    $errGateways = -1
    $errEnable = -1
    For $objNetAdapter in $colNetAdapters
        $errEnable = $objNetAdapter.EnableStatic($strIPAddress, $strSubnetMask)
        $errGateways = $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
    Next

    $objWMIService = 0
    $colNetAdapters = 0
    $objNetAdapter = 0
    Return (Not $errEnable)
EndFunc

Is at least easier than finding out what buttons to click :whistle:

Thanx for the advice did test it on a windows XP machine but does not seem to work but i'm just trying to see what you have done (code wise) maybe i'm doing something wrong,

but thanx alot

Share this post


Link to post
Share on other sites

Thanx for the advice did test it on a windows XP machine but does not seem to work but i'm just trying to see what you have done (code wise) maybe i'm doing something wrong,

but thanx alot

Take notice of the adaptername. The first parameter must contain the name of an existing and enabled adapter.

I have tested it on WinXP SP2 and it worked (at least on my machine).

Share this post


Link to post
Share on other sites

Take notice of the adaptername. The first parameter must contain the name of an existing and enabled adapter.

I have tested it on WinXP SP2 and it worked (at least on my machine).

my adaptername is Local Area Connection

so this is what i changed, maybe i'm doing something wrong.

StaticIpAddress("Local Area Connection", "192.168.10.165", "255.255.255.0", "192.168.10.1")

Exit

Func StaticIpAddress($szAdapterName, $szIP, $szSubnet, $szGateway, $iMetric = 1)
    Local $strIPAddress[1] = [$szIP]
    Local $strSubnetMask[1] = [$szSubnet]
    Local $strGateway[1] = [$szGateway]
    Local $strGatewayMetric[1] = [$iMetric]
   
    $objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
    $colNetAdapters = $objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE AND Description LIKE '" & $szAdapterName & "%'")

    $errGateways = -1
    $errEnable = -1
    For $objNetAdapter in $colNetAdapters
        $errEnable = $objNetAdapter.EnableStatic($strIPAddress, $strSubnetMask)
        $errGateways = $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
    Next

    $objWMIService = 0
    $colNetAdapters = 0
    $objNetAdapter = 0
    Return (Not $errEnable)
EndFunc

Share this post


Link to post
Share on other sites

So SO sO sorry what an idiot i am ADAPTER NAME !!!!

Thanx

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

So SO sO sorry what an idiot i am ADAPTER NAME !!!!

Thanx

Hi whiteball,

I am working on something similare, I think anyway.

With plenty help from this forum, the guys and gals are great on here.

Hope you can use this, give it a try and fiddel around, if you have any ideas what else can be added please let me know, maybe we can sort it out together.

I am now trying to get a child window open to edit/add/delete entries in an ini file where all the locations will be saved.

#include <GuiConstants.au3>
#include <Array.au3>
#include <Date.au3>
AutoItSetOption ( "TrayIconHide", 1 )
Opt ("GUIOnEventMode", 1)

Global $pb_progress1, $pb_plbl1

; GUI
; ===

GUICreate("IP Changer", 380, 520,-1,-1,"","")
GUISetIcon("Icons\AppIcon.ico")

; PIC
; ===

GUICtrlCreatePic("Icons\ZUDM.jpg", 0, 0, 160, 76)

; GROUP Message
; =============

GUICtrlCreateGroup("IP Address Changing Tool", 5, 20, 360, 0)
GUICtrlCreateLabel("This tool will help you to change your TCP/IP Address for the diffrent", 15, 40)
GUICtrlCreateLabel("ships you visit or to change your settings back to DHCP.", 15, 55)
GUICtrlCreateLabel("Before you start, contact the IT Officer for an availabe IP Address", 15, 70)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group

; IP Info Message
; ===============

GUICtrlCreateGroup("Your current Network settings", 5, 360, 200, 110)
GUICtrlCreateLabel("IP-Address:", 15, 380)
GUICtrlCreateLabel(@IPAddress1, 115, 380)
GUICtrlCreateLabel("Computer Name:", 15, 400)
GUICtrlCreateLabel(@ComputerName, 115, 400)
GUICtrlCreateLabel("Logged on user:", 15, 420)
GUICtrlCreateLabel(@UserName, 115, 420)
;GUICtrlCreateLabel("Preferred DNS:", 15, 440)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group


; PROGRESS
; ========

GUICtrlCreateLabel("Progress:", 120, 140)
 _Progress_Create(5,110,360,20)

; INPUT
; =====
GUICtrlCreateGroup("Network settings", 5, 170, 360, 160)
$IPAddress = GUICtrlCreateInput("", 110, 190, 130, 20)
GUICtrlCreateLabel("IP-Address:", 15, 195)
$SubNet = GUICtrlCreateInput("", 110, 215, 130, 20)
GUICtrlCreateLabel("Subnet Mask:", 15, 220)
$Gatway = GUICtrlCreateInput("", 110, 240, 130, 20)
GUICtrlCreateLabel("Default Gatway:", 15, 245)
$DNS1 = GUICtrlCreateInput("", 110, 265, 130, 20)
GUICtrlCreateLabel("Preferred DNS:", 15, 270)
$DNS2 = GUICtrlCreateInput("", 110, 290, 130, 20)
GUICtrlCreateLabel("WINS:", 15, 295)

; BUTTON
; ======

$buttonchangeIP = GUICtrlCreateButton("Change my IP", 250, 190, 100, 30, "")
$buttonresetIP = GUICtrlCreateButton("Reset to DHCP", 250, 235, 100, 30, "")
$buttonDone = GUICtrlCreateButton("Done/Exit", 250, 280, 100, 30, "")
GUICtrlSetOnEvent($buttonchangeIP, "button")
GUISetState()
GUICtrlSetOnEvent($buttonDone, "buttonDone")
GUICtrlSetOnEvent($buttonresetIP, "SetDHCP")
GUICtrlSetBkColor(-1, 0x00ff00)
WinSetOnTop("Date", "", 1)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group

; GUI MESSAGE LOOP
; ================

GUISetState()
While 1
    
; GUI Set Ctrl Read
; =================

    $IPAddressMessage = GUICtrlRead($IPAddress)
    $SubNetMessage = GUICtrlRead($SubNet)
    $GatwayMessage = GUICtrlRead($Gatway)
    $DNS1Message = GUICtrlRead($DNS1)
    $DNS2Message = GUICtrlRead($DNS2)
    
WEnd

Func buttonDone()
    Exit
EndFunc ;==>buttonDone

Func SetDHCP()
    Local $percent = 0
    $percent = 10
    _Progress_Update($percent)
    $percent = 20
    _Progress_Update($percent)
    $percent = 30
    _Progress_Update($percent)
    $percent = 40
    _Progress_Update($percent)
    $percent = 50
    _Progress_Update($percent)
    RunWait(@ComSpec & " /c " & 'netsh interface ip set address "Local Area Connection" dhcp', "", @SW_HIDE)
    $percent = 60
    _Progress_Update($percent)
    $percent = 70
    _Progress_Update($percent)
    
; Run NETSH as admin
    RunWait(@ComSpec & " /c " & 'netsh interface ip set dns "Local Area Connection" dhcp', "", @SW_HIDE)

    $percent = 80
    _Progress_Update($percent)
    $percent = 90
    _Progress_Update($percent)
    $percent = 100
    _Progress_Update($percent)
    
    MsgBox(496, "IP Changer by Craig Holohan", "Your TCP/IP settings have succesfully been changed to DHCP.")
    Exit
EndFunc ;==>SetDHCP

Func button()
; Start of Script Writer
; ======================
   
; Call netsh command
; ==================
    Local $percent = 0
    $percent = 10
    _Progress_Update($percent)
    $percent = 20
    _Progress_Update($percent)
    $percent = 30
    _Progress_Update($percent)
    $percent = 40
    _Progress_Update($percent)
    $percent = 50
    _Progress_Update($percent)
    RunWait(@ComSpec & " /c " & 'netsh interface ip set address name="Local Area Connection" static '& $IPAddressMessage &' '& $SubNetMessage &' '& $GatwayMessage &' 1' , "", @SW_HIDE)
    $percent = 95
    _Progress_Update($percent)
    RunWait(@ComSpec & " /c " & 'netsh interface ip set dns "Local Area Connection" static '& $DNS1Message &'', "", @SW_HIDE)
;RunWait(@ComSpec & " /c " & 'netsh interface ip set wins "Local Area Connection" static '& $DNS2Message &'', "", @SW_HIDE)
    $percent = 100
    _Progress_Update($percent)
    MsgBox(496, "IP Changer by Craig Holohan", "Your IP has sucsesfully been changed to "&@IPAddress1&".")
    Exit
EndFunc ;==>button

Func _Progress_Create($i_x, $i_y, $i_width, $i_height)
    $pb_progress1 = GUICtrlCreateProgress($i_x, $i_y, $i_width, $i_height, $PBS_SMOOTH)
   ;GUICtrlSetColor(-1, 32250); not working with Windows XP Style
    $pb_plbl1 = GUICtrlCreateLabel("0%", ($i_width / 2) + ($i_x / 2), $i_y + 30, 35, $i_height - 4, -1, $WS_EX_TRANSPARENT)
    GUICtrlSetFont(-1, -1, 800)
EndFunc ;==>_Progress_Create

Func _Progress_Update($i_percent)
    GUICtrlSetData($pb_progress1, $i_percent)
    GUICtrlSetData($pb_plbl1, $i_percent & "%")
EndFunc ;==>_Progress_Update

Cheers,

Craig

Edited by JdeB

Share this post


Link to post
Share on other sites

Nice Script from Dickb and nice GUI from craigholohan (very nice),

but I was wondering if there could be possiblity to list the Network Adaptors in GUI so the user can actually select which one to change.

Share this post


Link to post
Share on other sites

Never mind, made it work,

thanx anywyas

Share this post


Link to post
Share on other sites

Hi whiteball,

I am working on something similare, I think anyway.

With plenty help from this forum, the guys and gals are great on here.

Hope you can use this, give it a try and fiddel around, if you have any ideas what else can be added please let me know, maybe we can sort it out together.

I am now trying to get a child window open to edit/add/delete entries in an ini file where all the locations will be saved.

Cheers,

Craig

Dickb,

Thanks for this script works like a charm.

With plenty help from this forum, the guys and gals are great on here.

like You said its unbelieveble how much help i get from this forum.

thanx Whiteball

Share this post


Link to post
Share on other sites

Never mind, made it work,

thanx anywyas

Hey whiteball,

How did you get it to list the NIC's, I did it like below:

GUICtrlCreateGroup("Select Network connection", 5, 60, 280, 45)
Local $NIC_Conect = GUICtrlCreateCombo ("Select Network connection ---", 15,75,220)
GUISetState()
    Local $conitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
    If IsObj($conitems) Then
        For $objitem In $conitems
            If $objitem.netconnectionstatus = 2 Then GUICtrlSetData($NIC_Conect, $objitem.netconnectionid)
        Next
    EndIf
GUICtrlCreateGroup("", -99, -99, 1, 1)
[END CODE]

be interesting to see how you did it.

I am also trying to figure out how to check the users rights on the domain, if it is not sufficient i.e Admin rights to then Run the app as local Admin.
The plan is to have an option to right the local admin user Name and password to a .ini file and encrypt it.
So if the user has insuficient privelages it will run as local admin and retrieve the user name and password from a hidden .ini.

Cheers,
Craig


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
SHAHRAM   

    
        
    
             0
    
        
    

        
            
                Seeker
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             0
    
        
    

                39 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #13 · 
            Posted 
            
            
            
        
    

    


            
        
            
Hey whiteball,
How did you get it to list the NIC's, I did it like below:
I am not whiteball 

I am using a list box but there shouldn't be any problem with combo boxes,

I am using a simpler method 

GUICtrlCreateGroup("Please select the Network Adaptor you want to change:", 5, 20, 360, 140)
$mylist=GUICtrlCreateList ("Loading Network Adaptors...", 25,40,270,120)
GUICtrlSetLimit(-1,200)
GUICtrlCreateGroup("", -99, -99, 1, 1)

; FINDING NETWORK ADAPTORS
; ================
NetAdap()

Func NetAdap()
    $cmd    = "netsh interface ip show config"
    $quotes = chr(34)
    $line   = ""

    $foo = Run($cmd, @SystemDir, @SW_HIDE, $STDOUT_CHILD)

    While 1
        $line &= StdoutRead($foo)
        If @error Then ExitLoop
    WEnd

    $adaptorNames = ExtractStrBetweenChars($line, $quotes)
    
        If $adaptorNames[0] = 0 Then
        GUICtrlSetData($mylist,"")
        GUICtrlSetData($mylist,"No Adaptor Was Found")
    Else
        $line = ""
        GUICtrlSetData($mylist,"")
        For $i = 1 To $adaptorNames[0] Step 1
        GUICtrlSetData($mylist,$adaptorNames[$i])
        Next
    EndIf
EndFunc

Func ExtractStrBetweenChars($str, $char)
    Dim $array[1]
    
    $occurrence = 0

    While 1
        $occurrence += 1
        
        $start = StringInStr($str, $char, 0, $occurrence)
        
        If $start = 0 Then 
            ExitLoop
        Else
            $occurrence += 1
            $stop = StringInStr($str, $char, 0, $occurrence) - 1
        EndIf
        
        _ArrayAdd($array, StringMid($str, $start + 1, $stop - $start))
    WEnd
    
    $array[0] = UBound($array) - 1
    
    Return $array
EndFunc

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