Jump to content

Check to see if IP address is Asigned by DHCP


_Chris_
 Share

Recommended Posts

As the title says i need to check whether the ip address of a machine is assign by the dhcp or statically assigned.

You can check it in the registry (I'm not on a windows box, so I can't point to the key right now), or you could parse the output of IPCONFIG /ALL for the "DHCP Enabled?" line.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

C'MON someone must know how to do this!! Im getting desperate here!

Desperate... and lazy? :)

Anyway, if you had used my earlier comment and searched HKLM for DHCP, it would have lead you to the key(s) at:

HKLM\SYSTEM\ControlSet001\Services\$GUID\Parameters\Tcpip

The variable $GUID is a globaly unique identifier for each NIC, i.e. {3C6F5189-B96D-4684-96E4-0E7C2B8FFD61}

In the Tcpip key for each NIC is a REG_DWORD value called EnableDHCP. If the registry search/read is beyond your skill set, use the IPCONFIG method mentioned earlier:

IPCONFIG /ALL | FIND /I "Dhcp Enabled"

Carpe Denim!* Put your pants on and get busy!

:P

*Latin: "Seize the jeans!"

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

As the title says i need to check whether the ip address of a machine is assign by the dhcp or statically assigned.

if you are talking about the local machine, do what PsaltyDS said.

If you are talking about ANY machine on the network, then no there is no way to tell if the IP addr. was assigned by a DHCP server without access to that DHCP server (to check the current leases).

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Thanks PSaltyDS for your help. Im actually not lazy, just stuck. I am doing lots of coding and moved onto somthing else. Your information has provided me with the best help yet. The registry option is no good because there is no easy way to dermind which conection is which. And suggesting things are not within the realms of my capability is frankly insulting and uncalled for. When people ask for help they dont need ego.

Link to comment
Share on other sites

Thanks PSaltyDS for your help. Im actually not lazy, just stuck. I am doing lots of coding and moved onto somthing else. Your information has provided me with the best help yet. The registry option is no good because there is no easy way to dermind which conection is which. And suggesting things are not within the realms of my capability is frankly insulting and uncalled for. When people ask for help they dont need ego.

What's insulting and uncalled for his creating two threads where you ask the same thing.

What's insulting and uncalled for is creating a second thread when you got the answer, including code, in the first thread.

What's insulting and uncalled for is asking people to write code for you, especially after they've pointed you in the right direction, or in your case, you've been given code in another thread.

What proof have you demonstrated that your abilities are capable of this task? All I see are two threads, neither of which contain any code by you. In both of these threads you are told the answer but continue on asking for a solution unabated. So who's being "insulting and uncalled"?

Link to comment
Share on other sites

I dont claim to be an expert at coding in auto it, but i am trying. I have got SOME of the answer i was looking for but as yet i havent been able to get the exact result i am looking for. The REG method dosent give me a solid answer. The DOS way is good (and if you look i said this was good) but i am still trying to work out how to narrow down the output to only look at ONE connection, i can get it down to querying all connections and displaying YES,NO, YES. This isnt what i am looking for. If you want to see a sample of code to see im not an idiot... here it is,

CODE

#include <GUIConstants.au3>

#include <Process.au3>

#Region ### Form Controls ###

Opt("OnExitFunc", "closeclicked")

TraySetState (2)

$SSST = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Starting Remote Assistance Software",10,15,180,40)

GUISetState(@SW_SHOW,$SSST)

_RunDos('netsh interface ip set address name="Wireless Network Connection" dhcp')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" dhcp')

GUIDelete($SSST)

Call("TEST")

$Main = GUICreate("TT Remote Support ", 570, 295, -1, -1)

GUISetBkColor(0xFFFFFF)

GUISetState(@SW_HIDE,$Main)

GUISetFont (12, 400)

GUICtrlCreatePic("pic.bmp",310,0,260,269)

$Group1 = GUICtrlCreateGroup("Please Select a Remote Assistance Channel ", 8, 6, 290, 280, $WS_CLIPSIBLINGS)

GUICtrlSetFont (-1,9, 400)

$REM1 = GUICtrlCreateRadio("Remote Assistance 1 (Port 433)", 32, 30, 255, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM1S = GUICtrlCreateLabel("Status:", 80, 50, 150, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM2 = GUICtrlCreateRadio("Remote Assistance 2 (Port 110)", 32, 70, 255, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM2S = GUICtrlCreateLabel("Status:", 80, 90, 150, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM3 = GUICtrlCreateRadio("Remote Assistance 3 (Port 443)", 32, 110, 255, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM3S = GUICtrlCreateLabel("Status:", 80, 130, 150, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM4 = GUICtrlCreateRadio("Remote Assistance 4 (Port 143)", 32, 150, 255, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM4S = GUICtrlCreateLabel("Status:", 80, 170, 150, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM5 = GUICtrlCreateRadio("Remote Assistance 5 (Port 119)", 32, 190, 255, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$REM5S = GUICtrlCreateLabel("Status:", 80, 210, 150, 17)

GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)

$Stop = GUICtrlCreateButton("Stop", 156, 245, 118, 25, 0)

$Start = GUICtrlCreateButton("Start", 32, 245, 118, 25, 0)

$MFile = GUICtrlCreateMenu("File")

$MReset = GUICtrlCreateMenuItem("Reset", $MFile)

$MRefresh = GUICtrlCreateMenuItem("Refresh", $MFile)

$MExit = GUICtrlCreateMenuItem("Exit", $MFile)

$MHelp = GUICtrlCreateMenu("Help")

$MAbout = GUICtrlCreateMenuItem("About", $MHelp)

Call("GetPortStatus")

GUISetState(@SW_SHOW, $Main)

SplashOff()

#EndRegion ### Form Controls ###

Do

$msg=GUIGetMsg()

$REM1R= GUICtrlRead($REM1)

$REM2R= GUICtrlRead($REM2)

$REM3R= GUICtrlRead($REM3)

$REM4R= GUICtrlRead($REM4)

$REM5R= GUICtrlRead($REM5)

Select

Case $Msg = $MExit

exit

Case $msg=$MRefresh

Call("GetPortStatus")

Case $Msg=$Stop

GUISetState(@SW_DISABLE,$Main)

$SSSTOP = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUISetState(@SW_SHOW,$SSSTOP)

GUICtrlCreateLabel("Stopping Remote Assistance Software",5,15,190,40)

ProcessClose("viewer.exe")

_RunDos('netsh interface ip set address name="Wireless Network Connection" dhcp')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" dhcp')

GUIDelete($SSSTOP)

call("TEST")

Call("GetPortStatus")

GUISetState(@SW_ENABLE,$Main)

Case $Msg = $MAbout

GUISetState(@SW_DISABLE,$Main)

$message= "Version Number: v0.2" & @LF & "Written by: 'CJ' of Target Tracker" & @LF & "Written using: Autoit v3" & @LF & "Contact: cj.smith@essexcc.gov.uk" & @LF & "Remote Support Provided by Dualdesk"

$sp= SplashTextOn("About TT Remote Assistance", $message,250,100,-1,-1,33,"",9)

Do

$about=GUIGetMsg()

Until $about = $GUI_EVENT_PRIMARYDOWN

SplashOff()

GUISetState(@SW_ENABLE,$Main)

Case $Msg = $MReset

GUISetState(@SW_DISABLE,$Main)

$SSRESET = GUICreate("Please Wait...",200,100,-1,-1,"",$WS_EX_TOOLWINDOW)

GUISetState(@SW_SHOW,$SSRESET)

GUICtrlCreateLabel("Reseting Remote Assistance Software",25,15,180,40)

_RunDos('netsh interface ip set address name="Wireless Network Connection" dhcp')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" dhcp')

if ProcessExists("viewer.exe") Then

ProcessClose("viewer.exe")

Endif

Call("Getportstatus")

GUIDelete($SSRESET)

GUISetState(@SW_ENABLE,$Main)

Case $Msg=$Start

Select

Case $REM1R = $Gui_Checked

GUISetState(@SW_DISABLE,$Main)

$SSR1 = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Configuring Remote Assistance 1",20,15,180,40)

GUISetState(@SW_SHOW)

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.14 mask=255.255.255.0')

_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')

_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

Run('"C:\Program Files\Advantig\DualDesk Viewer\Viewer.exe" -preset 4 -dotcursor -nowarnings -logfile DualDesk.log -listen 433')

GUICtrlSetData ( $REM1S,"Status: LISTENING")

GUICtrlSetState($MREFRESH,$GUI_Disable)

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_ENABLE)

GUICtrlSetState($REM2,$GUI_Disable)

GUICtrlSetState($REM2S,$GUI_Disable)

GUICtrlSetState($REM3,$GUI_Disable)

GUICtrlSetState($REM3S,$GUI_Disable)

GUICtrlSetState($REM4,$GUI_Disable)

GUICtrlSetState($REM4S,$GUI_Disable)

GUICtrlSetState($REM5,$GUI_Disable)

GUICtrlSetState($REM5S,$GUI_Disable)

GUIDelete($SSR1)

Call("test")

GUISetState(@SW_ENABLE,$Main)

Case $REM2R = $Gui_Checked

GUISetState(@SW_DISABLE,$Main)

$SSR2 = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Configuring Remote Assistance 2",20,15,180,40)

GUISetState(@SW_SHOW)

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.18 mask=255.255.255.0')

_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')

_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

Run('"C:\Program Files\Advantig\DualDesk Viewer\Viewer.exe" -preset 4 -dotcursor -nowarnings -logfile DualDesk.log -listen 110')

GUICtrlSetData ( $REM2S,"Status: LISTENING")

GUICtrlSetState($MREFRESH,$GUI_Disable)

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_ENABLE)

GUICtrlSetState($REM1,$GUI_Disable)

GUICtrlSetState($REM1S,$GUI_Disable)

GUICtrlSetState($REM3,$GUI_Disable)

GUICtrlSetState($REM3S,$GUI_Disable)

GUICtrlSetState($REM4,$GUI_Disable)

GUICtrlSetState($REM4S,$GUI_Disable)

GUICtrlSetState($REM5,$GUI_Disable)

GUICtrlSetState($REM5S,$GUI_Disable)

GUIDelete($SSR2)

Call("test")

GUISetState(@SW_ENABLE,$Main)

Case $REM3R = $Gui_Checked

GUISetState(@SW_DISABLE,$Main)

$SSR3 = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Configuring Remote Assistance 3",20,15,180,40)

GUISetState(@SW_SHOW)

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.11 mask=255.255.255.0')

_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')

_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

Run('"C:\Program Files\Advantig\DualDesk Viewer\Viewer.exe" -preset 4 -dotcursor -nowarnings -logfile DualDesk.log -listen 443')

GUICtrlSetData ( $REM3S,"Status: LISTENING")

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($MREFRESH,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_ENABLE)

GUICtrlSetState($REM1,$GUI_Disable)

GUICtrlSetState($REM1S,$GUI_Disable)

GUICtrlSetState($REM2,$GUI_Disable)

GUICtrlSetState($REM2S,$GUI_Disable)

GUICtrlSetState($REM4,$GUI_Disable)

GUICtrlSetState($REM4S,$GUI_Disable)

GUICtrlSetState($REM5,$GUI_Disable)

GUICtrlSetState($REM5S,$GUI_Disable)

GUIDelete($SSR3)

Call("test")

GUISetState(@SW_ENABLE,$Main)

Case $REM4R = $Gui_Checked

GUISetState(@SW_DISABLE,$Main)

$SSR4 = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Configuring Remote Assistance 4",20,15,180,40)

GUISetState(@SW_SHOW)

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.10 mask=255.255.255.0')

_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')

_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

Run('"C:\Program Files\Advantig\DualDesk Viewer\Viewer.exe" -preset 4 -dotcursor -nowarnings -logfile DualDesk.log -listen 143')

GUICtrlSetData ( $REM4S,"Status: LISTENING")

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($MREFRESH,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_ENABLE)

GUICtrlSetState($REM1,$GUI_Disable)

GUICtrlSetState($REM1S,$GUI_Disable)

GUICtrlSetState($REM3,$GUI_Disable)

GUICtrlSetState($REM3S,$GUI_Disable)

GUICtrlSetState($REM2,$GUI_Disable)

GUICtrlSetState($REM2S,$GUI_Disable)

GUICtrlSetState($REM5,$GUI_Disable)

GUICtrlSetState($REM5S,$GUI_Disable)

GUIDelete($SSR4)

Call("test")

GUISetState(@SW_ENABLE,$Main)

Case $REM5R = $Gui_Checked

GUISetState(@SW_DISABLE,$Main)

$SSR5 = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Configuring Remote Assistance 5",20,15,180,40)

GUISetState(@SW_SHOW)

_RunDos('netsh interface ip set address name="Wireless Network Connection" source=static addr=192.168.1.12 mask=255.255.255.0')

_RunDos('netsh interface ip set address name="Wireless Network Connection" gateway=192.168.1.1 gwmetric=0')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" source=static addr=194.74.65.68')

_RunDos('netsh interface ip add dns name = "Wireless Network Connection" addr = 194.74.65.69')

Run('"C:\Program Files\Advantig\DualDesk Viewer\Viewer.exe" -preset 4 -dotcursor -nowarnings -logfile DualDesk.log -listen 119')

GUICtrlSetData ( $REM5S,"Status: LISTENING")

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($MREFRESH,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_ENABLE)

GUICtrlSetState($REM1,$GUI_Disable)

GUICtrlSetState($REM1S,$GUI_Disable)

GUICtrlSetState($REM3,$GUI_Disable)

GUICtrlSetState($REM3S,$GUI_Disable)

GUICtrlSetState($REM4,$GUI_Disable)

GUICtrlSetState($REM4S,$GUI_Disable)

GUICtrlSetState($REM2,$GUI_Disable)

GUICtrlSetState($REM2S,$GUI_Disable)

GUIDelete($SSR5)

Call("test")

GUISetState(@SW_ENABLE,$Main)

Case $REM1R = $Gui_UnChecked AND $REM2R = $Gui_UnChecked AND $REM3R = $Gui_UnChecked AND $REM4R = $Gui_UnChecked AND $REM5R = $Gui_UnChecked

GUISetState(@SW_DISABLE,$Main)

MsgBox(0x40,"Remote Support","Please Select a Remote Assistance Channel")

GUISetState(@SW_ENABLE,$Main)

EndSelect

EndSelect

Until $msg= $GUI_EVENT_CLOSE

Func Test()

$Setupsub = GUICreate("Please Wait...",200,90,-1,-1,"",$WS_EX_TOOLWINDOW)

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Making Network Connection",30,15,180,20)

$Cancel = GUICtrlCreateButton("Cancel",50,35,100,20)

Do

$msg= GUIGetMsg()

$pres=ping("192.168.1.1",250)

Select

Case $msg = $Cancel

EXIT

Exitloop

Case $pres>"0"

GUIDelete($setupsub)

Exitloop

ENdselect

Until $pres>"0"

Endfunc

Func CloseClicked()

if ProcessExists("viewer.exe") Then

ProcessClose("viewer.exe")

Endif

GUISetState(@SW_DISABLE,$Main)

$SSCL = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Closing Remote Remote Assistance",13,15,180,40)

GUISetState(@SW_SHOW,$SSCL)

ProcessClose("viewer.exe")

_RunDos('netsh interface ip set address name="Wireless Network Connection" dhcp')

_RunDos('netsh interface ip set dns name="Wireless Network Connection" dhcp')

GUIDelete($SSCL)

Exit

EndFunc

Func GetPortStatus()

GUISetState(@SW_DISABLE,$Main)

GUICtrlSetState($MREFRESH,$GUI_Enable)

$SSPS = GUICreate("Please Wait...",200,70,-1,-1,"",$WS_EX_TOOLWINDOW)

GUICtrlCreateLabel("Scanning for all Available Ports",25,15,180,40)

GUISetState(@SW_SHOW,$SSPS)

$110 = Ping("192.168.1.18",250)

$119 = Ping("192.168.1.12",250)

$143 = Ping("192.168.1.10",250)

$433 = Ping("192.168.1.14",250)

$443 = Ping("192.168.1.11",250)

if $433 Then ;110

GUICtrlSetState ( $REM1, $GUI_DISABLE)

GUICtrlSetState ( $REM1S, $GUI_DISABLE)

GUICtrlSetData ( $REM1S,"Status: Busy")

Else

GUICtrlSetState ( $REM1, $GUI_ENABLE)

GUICtrlSetState ( $REM1S, $GUI_ENABLE)

GUICtrlSetData ( $REM1S,"Status: Free")

Endif

if $110 Then ;119

GUICtrlSetState ( $REM2, $GUI_DISABLE)

GUICtrlSetState ( $REM2S, $GUI_DISABLE)

GUICtrlSetData ( $REM2S,"Status: Busy")

Else

GUICtrlSetState ( $REM2, $GUI_ENABLE)

GUICtrlSetState ( $REM2S, $GUI_ENABLE)

GUICtrlSetData ( $REM2S,"Status: Free")

Endif

if $443 Then ;110

GUICtrlSetState ( $REM3, $GUI_DISABLE)

GUICtrlSetState ( $REM3S, $GUI_DISABLE)

GUICtrlSetData ( $REM3S,"Status: Busy")

Else

GUICtrlSetState ( $REM3, $GUI_ENABLE)

GUICtrlSetState ( $REM3S, $GUI_ENABLE)

GUICtrlSetData ( $REM3S,"Status: Free")

Endif

if $143 Then ;110

GUICtrlSetState ( $REM4, $GUI_DISABLE)

GUICtrlSetState ( $REM4S, $GUI_DISABLE)

GUICtrlSetData ( $REM4S,"Status: Busy")

Else

GUICtrlSetState ( $REM4, $GUI_ENABLE)

GUICtrlSetState ( $REM4S, $GUI_ENABLE)

GUICtrlSetData ( $REM4S,"Status: Free")

Endif

if $119 Then ;110

GUICtrlSetState ( $REM15, $GUI_DISABLE)

GUICtrlSetState ( $REM5S, $GUI_DISABLE)

GUICtrlSetData ( $REM5S,"Status: Busy")

Else

GUICtrlSetState ( $REM5, $GUI_ENABLE)

GUICtrlSetState ( $REM5S, $GUI_ENABLE)

GUICtrlSetData ( $REM5S,"Status: Free")

Endif

if not ProcessExists("Viewer.exe") Then

GUICtrlSetState($REM1,$GUI_UNCHECKED)

GUICtrlSetState($REM2,$GUI_UNCHECKED)

GUICtrlSetState($REM3,$GUI_UNCHECKED)

GUICtrlSetState($REM4,$GUI_UNCHECKED)

GUICtrlSetState($REM5,$GUI_UNCHECKED)

GUICtrlSetState($Stop,$GUI_Disable)

GUICtrlSetState($Start,$GUI_Enable)

Else

GUICtrlSetState($Start,$GUI_Disable)

GUICtrlSetState($Stop,$GUI_Enable)

EndIf

GUIDelete($SSPS)

GUISetState(@SW_ENABLE,$Main)

EndFunc

You will probably run that down and say it sucks, but just so you know im not lazy, im simply looking for help. Im sorry for multi posting, i couldnt find my previous post to add to it, i have now realised how to get back to them when nothing has been updated on them.

Edited by Larry
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...