Jump to content

Address IP Static or DHCP


 Share

Recommended Posts

  • Moderators
Local $oWMI, $oNICs

    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        If IsObj($oWMI) Then
            $oNICs = $oWMI.ExecQuery("Select * From Win32_NetworkAdapterConfiguration")
                If IsObj($oNICs) Then
                    For $sNIC In $oNICs
                        ConsoleWrite("For " & $sNIC.Description & ": " & $sNIC.DHCPEnabled & @CRLF)
                    Next
                Else
                    ConsoleWrite("Unable to pull NIC info from WMI" & @CRLF)
                EndIf
        Else
            ConsoleWrite("Unable to connect to WMI" & @CRLF)
        EndIf

 

"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

 

This can be corrected?

$objWMI = ObjGet("winmgmts:\\.\root\cimv2")
$collection = $objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")


For $obj In $collection
    If $obj.DHCPEnabled = -1 Then
        $DHCPStatus = "TRUE"
        ConsoleWrite($DHCPStatus)
    Else
        $DHCPStatus = "FALSE"
        ConsoleWrite($DHCPStatus)
     EndIf
Next

 

Link to comment
Share on other sites

  • Moderators

I'm not sure what you mean by "dates of the network card"? But if you're looking for just the physical NIC for example you could do something like this:

Local $oWMI, $oNICs

    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        If IsObj($oWMI) Then
            $oNICs = $oWMI.ExecQuery("Select * From Win32_NetworkAdapterConfiguration")
                If IsObj($oNICs) Then
                    For $sNIC In $oNICs
                        If StringInStr($sNIC.Caption, "Ethernet") Then ConsoleWrite("For " & $sNIC.Caption & ": " & $sNIC.DHCPEnabled & @CRLF)
                    Next
                Else
                    ConsoleWrite("Unable to pull NIC info from WMI" & @CRLF)
                EndIf
        Else
            ConsoleWrite("Unable to connect to WMI" & @CRLF)
        EndIf

There are a myriad of other ways to go about it, like $sNIC.IPAddress, etc. I suggest you search the forum for Scriptomatic to see what options are open to you.

"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

Local $oWMI = ObjGet("winmgmts:root\CIMV2")
Local $oDHCP = $oWMI.ExecQuery("Select * from WIN32_NetworkAdapterConfiguration Where IPEnabled = True And DHCPEnabled = True")
MsgBox(0, "", "Computer is set to " & ($oDHCP.Count ? "DHCP" : "Static" )  )

 

Link to comment
Share on other sites

  • Moderators

The only problem I can see with that approach (and it is admittedly a less common occurrence) is a dual-homed machine with different settings. I've run into it a couple of times at different companies.

"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

You're right. Usually, In my corporate network, I make the difference by checking the Ip address subnet, the default gateway or the IP address of the DHCP Server.

BTW, the computer can be connecter with both ethernet and wireless connection...

 

Link to comment
Share on other sites

  • 2 years later...

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

×
×
  • Create New...