Jump to content

Get Default Gateway and Subnet IP help


Go to solution Solved by jguinch,

Recommended Posts

Could some one help me out. I dont know how to get the Default Gateway and Subnet IP added to my script from the local computer. Line 36 and 37

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

#Region ### START Koda GUI section ### Form=H:\Form1.kxf
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_info()
Func _info()
    $username = @UserName
    $CPUArch = @CPUArch
    $OsVersion = @OSVersion
    $OSArch = @OSArch
    $Computername = @ComputerName
    $ipaddress = @IPAddress1

    $objWMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\CIMV2')
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=true")
    For $objAdapter  In $colItems
    If $objAdapter.MACAddress <> "" Then
    Local $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime")
        $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName  & "\root\cimv2")
        $colOperatingSystems = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For $objOperatingSystem in $colOperatingSystems
        $dtmConvertedDate.Value = $objOperatingSystem.InstallDate
        $dtmInstallDate = $dtmConvertedDate.GetVarDate
    If $dtmInstallDate <> "" Then
        MsgBox(4096, "System Infomation", "OSD Version:  " & "Build" & @CRLF & _
        "Computer Name is:  "& $Computername & @CRLF & _
        "Install date is:  "& _WMIDateStringToDate($dtmInstallDate)& @CRLF & _
        "CPU architecture is:  "& $CPUArch & @CRLF & _
        "OS Version is:  "&$OsVersion & " " & $OSArch & " Bit" & @CRLF & _
        "MAC Address is:  "& $objAdapter.MACAddress & @CRLF & _
        "IP Address is:  "& $ipaddress & @CRLF & _
        "Default Gateway:  "& "DefaultGateway" & @CRLF & _
        "Subnet Mask :  "& "Subnet Mask " & @CRLF & @CRLF & _
        "To Copy: Press CTRL+C  ")
    EndIf
Next
    EndIf
    Next
EndFunc

Func _WMIDateStringToDate($dtmInstallDate)
    Return StringRegExpReplace($dtmInstallDate,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$2/$3/$1 $4:$5:$6")
EndFunc
Link to comment
Share on other sites

  • Solution

Try this :

$DefaultGateway = $objAdapter.DefaultIPGateway[0]
$mask = $objAdapter.IPSubnet[0]

If you have more than one gateway or subnet mask, you can use DefaultIPGateway[0], DefaultIPGateway[1] ... or $objAdapter.IPSubnet[0], $objAdapter.IPSubnet[1]...

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...