Download the Tom's Hardware App from the App Store
The reference for current tech news
Yes No
Ads
Tom's Hardware > Forum > Windows XP > General Discussion > Pull IP address from file and output Computer Name

Pull IP address from file and output Computer Name

Forum Windows XP : General Discussion Pull IP address from file and output Computer Name

Word :    Username :           
 

I have a file that includes IP addresses of all PC\'s on our network. I need to pull the IP address from the file and run a command to output the IP address and the Computer Name. Here is what I\'ve come up with and this works if the file only has the IP address. My file has more than one column of information? Please help.

@echo off
set IPList=C:\temp\list.txt
Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%A in ("%IPList%" ) do (
for /f "tokens=2 delims= " %%B in ('ping -a %%A -n 1 -w 500 ^|findstr Pinging') do (
set PCName=%%B
echo %%A,!PCName:~0,-1!>>final.csv
))

Reply to goreb13
Register or log in to remove.

Use VBscript it's much more flexible as it lets you open the file and read it with more control.

Here is a similar script I wrote to delete computers from AD automatically, it reads a spreadsheet to get the names. You can just use the code needed to read in data, and write different code to manipulate it using the call function.

The r=2 is what sets the Row it will read. If you play around with that you will bea ble to read whichever row or rows you need.


'**** Delete old and unused computer accounts from Active Directory
'**** Reads computer names from an Excel file
'**** Author: ME!
'**** 1/18/08

On Error Resume Next

'**** Define some constants ****
Const FOR_READING = 1
Const ForAppending = 8
Dim CompName
Set WshShell = WScript.CreateObject("WScript.Shell" )
Set objFSO = CreateObject("Scripting.FileSystemObject" )

'**** Set Excel object and path to spreadsheet containing PC names ****
Set objExcel = WScript.CreateObject ("excel.application" )
objExcel.DisplayAlerts = 0
Set PathExcel = objExcel.WorkBooks.Open _
("C:\Scripts\DeleteOldPC\AD365.xls", False, True)

r = 2
Do until len(objExcel.cells(r, 1).value) = 0


'**** Set variable for computer name to ping from row r, column 1 of spreadsheet ****
strComputer = objExcel.cells(r, 1).Value

Set objShell = CreateObject("WScript.Shell" )
'WScript.Echo strComputer
objExec = objShell.Run("ping -n 2 -w 2000 " & strComputer, 7, True)

If objExec = 0 Then
Call PCExists
Else
Call DeleteFromAD
End If

r=r+1
Loop

WScript.Echo "Script Completed"
WScript.Quit

'**** Skip deleting the computer account if the machine is pingable ****
Sub PCExists()
'**** Write computer skipped to log file ****
Set Results= objFSO.OpenTextFile _
("C:\Scripts\DeleteOldPC\Delete_From_AD_Results.csv", ForAppending, True)
Results.Write strComputer & ", Not Deleted From AD At , " & Now() & vbCrLf
Results.Close
End Sub

'**** Delete computer account from AD if machine is not pingable ****
Sub DeleteFromAD()
Set objComputer = GetObject("LDAP://CN=" & strComputer & _
",CN=Computers,DC=umassmemorial,DC=org" )
objComputer.DeleteObject (0)

'**** Write success to log file ****
Set Results= objFSO.OpenTextFile _
("C:\Scripts\DeleteOldPC\Delete_From_AD_Results.csv", ForAppending, True)
Results.Write strComputer & ", Deleted From AD At , " & Now() & vbCrLf
Results.Close
End Sub


Message edited by hang-the-9 on 08-22-2011 at 11:27:13 PM
Reply to hang-the-9
Tom's Hardware > Forum > Windows XP > General Discussion > Pull IP address from file and output Computer Name
Go to:

There are 1956 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
  • Ask the community now
  • Publish
Ad
Ads
Latest best answer
Password
By ksiemb, 22 hours ago:


Cannot help with password retrieval. - Forum Rules.

Best offers
They won a badge
Join us in greeting them
Top experts