Sign in to follow this  
Followers 0
_Chris_

Chrck if IP address is set to auto configure

8 posts in this topic

I am making an ip switcher for use with remote support software, i have a dos code to change the computers ip address:

netsh interface ip set address name="Wireless Network Connection" dhcp

netsh interface ip set dns name="Wireless Network Connection" dhcp

What i need is a way of checking whether the IP is set to auto or not. Any ideas??

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Parse ipconfig /all ...

My output looks like this

DHCP-aktiviert. . . . . . . . . . : Nein

You could also do a

RegRead at HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\??? and search for the key EnableDHCP.

Edited by dabus

Share this post


Link to post
Share on other sites

Yeah i knew how to do that but How could i automate this using autoit?

Share this post


Link to post
Share on other sites

Global $DirOutputOnce

$DirOutput = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 2)
        While 1
            $DirData = StdoutRead($DirOutput)
            If @error Then ExitLoop
            If $DirData Then
                $DirOutputOnce &= $DirData
            Else
                Sleep(10)
            EndIf
        WEnd
        ; Remove spaces from output
        $DirOutputOnce = StringStripWS($DirOutputOnce, 3)
        ; Split output into array
        $DirSplit = StringSplit($DirOutputOnce, @CRLF, 1)
        For $i = 1 To $DirSplit[0]
            MsgBox(1,1,$DirSplit[$i])
        
        Next

Keep in mind that each language will have difftrent output.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Also as dabus stated it would be even better to use REGISTRY as it's the same language in all windows versions. But you gotta play yourself with it and check in regedit what you realy need to achieve :) Here's sample.

For $i= 1 to 10
    $var = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $i)
    If @error <> 0 then ExitLoop
    $reg = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $var, "EnableDHCP")
    
    If $reg = 1 Then $dhcp = "Yes"
    If $reg = 0 Then $dhcp = "No"
    MsgBox(4096, "SubKey #" & $i & " under HKLM\Software: ", $var & " - DHCP: " & $dhcp)
Next

Dabus: of course suggestions are nice, but nicer is to give someone some code so he can work with something, especially if he's just starting. I'm not saying to make all his work for him but when i started i prefered to be given some code instead of just "you can try this" and 0 code :P


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Thanks guys, this is all briliant. I am new to autoit but i have written some fantastic scripts and love the program. I really apresciate all the help i get on here!

The reg way is briliant but is there a way to get it to only look for one network conection, i want it to check the conection used for the remote assistance. This is defined in an ini file and i can get it to read from the file.

The program im writing changes the ip address to autoasign by dhcp on startup, this slows it down and isnt necisary if the ip is already auto asigned.

Share this post


Link to post
Share on other sites

Well it's hard to say what network connection you are realy looking for .. you should open regedit now and check on your computer what more then just "DHCP ENABLED" can tell you if your connection is the one you're looking for. I would check if the IP is assigned by DHCP and if it matches lets say 192.168.*.* or not. For example if value DhcpIPAddress or DhcpServer server is the one matching yours. That way you could tell if it's interface you're looking for or not. Well you gotta play with it.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

yeah that was my first thought, i checked the registry to see if there way any way to identify the connection, but as it happens, my wireless ip address for work is in the same scope as my wired address at home, cos its a 192.168.1.* addy! Maybe the dos aproach yield an answer...

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