Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

How can i find the subnet of a remote machine

Hi,

I want to find the subnet  of all machines in the file.

Is there a way to do it remotely.

Regards
Sharath
ASKER CERTIFIED SOLUTION
Avatar of Alan Huseyin Kayahan
Alan Huseyin Kayahan
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
  If you can get replies, that means it is in the subnet of server
Avatar of bsharath

ASKER

MrHusy

I just wanted this to be shared with you.
This can get all the details of network card to a file.

Machinenames has to be in the machinelist.txt

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "IP Address"
objExcel.Cells(1, 3).Value = "Subnet Mask"
objExcel.Cells(1, 4).Value = "Default Gateway"
objExcel.Cells(1, 5).Value = "MAC Address"

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CimV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IpEnabled = True")

For Each objItem in colItems
strIpAddress = Join(objItem.IpAddress)
strIpSubnet = Join(objItem.IpSubnet)
strDefaultGateway = Join(objItem.DefaultIpGateway)

objExcel.Cells(intRow, 1).Value = UCase(objItem.DnsHostName)
objExcel.Cells(intRow, 2).Value = strIPAddress
objExcel.Cells(intRow, 3).Value = strIPSubnet
objExcel.Cells(intRow, 4).Value = strDefaultGateway
objExcel.Cells(intRow, 5).Value = objItem.MacAddress
intRow = intRow + 1
Next

objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
loop

Wscript.Echo "Done"


Regards
Sharath
     Hi Sharath
             Thanks for your share :). This script works as far as the remote machine is in the same subnet. But it can not get the details of a machine in different subnet because it can not establish a network connectivity to that different subnet.

Regards