Syntax to resolve hostname

I need a command that will look at file hostname.txt and produce an ip.txt from it.  Assistance is greatly appreciated.
frugalmuleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guru JiCommented:
I had used this script below before and it worked. Hope it might be helpful to you as well. This script will take your hostname.txt and will produce ip csv file.

@echo off
set HostList=C:\hostFileName.txt

Echo Computername,IP Address>IPAddress.csv
setlocal enabledelayedexpansion

for /f “usebackq tokens=*” %%A in (“%HostList%”) do (
for /f “tokens=3” %%B in (‘ping -n 1 -l 1 %%A ^|findstr Reply’) do (
set IPadd=%%B
echo %%A,!IPadd:~0,-1!>>IPAddress.csv
))
David Johnson, CD, MVPOwnerCommented:
Powershell
#requires -version 4
$hostnames =get-content c:\test\hostnames.txt
$output = @()
foreach ($hostname in $hostnames){
    $connection = test-netconnection $hostname  -ErrorAction SilentlyContinue | select Computername,remoteaddress  
    if ($connection.RemoteAddress -eq $null) { $connection.RemoteAddress = "Not Reachable" }
    $object = New-Object PsObject -Property @{
            "Hostname" = $connection.ComputerName
            "IP_Address" = $connection.remoteaddress
            }
    $output += $object

    }
$output | ConvertTo-Csv -nti | Out-File c:\test\ip.csv

Open in new window

frugalmuleAuthor Commented:
Thanks Ji and David.  It appears that running Powershell scripts is disabled.  However, the script below does produce an Output.csv file with two named columns, but no actual data.
@echo off
 set HostList=C:\Hostnames.txt

 Echo Hostname,IP>Output.csv
 setlocal enabledelayedexpansion

 for /f “usebackq tokens=*” %%A in (“%HostList%”) do (
 for /f “tokens=3” %%B in (‘ping -n 1 -l 1 %%A ^|findstr Reply’) do (
 set IPadd=%%B
 echo %%A,!IPadd:~0,-1!>>Output.csv
 ))

Open in new window

Guru JiCommented:
Hi Frugamule.

Make sure you have full access to C:\Hostnames.txt and the name of the file is exactly same (Case sensitive). The above script worked for me.

Worst you can also try this tool, which does same thing but instead you can copy and paste all hostnames into it all at once.

Let me know above if your file name Hostnames.txt  is exact same or not and do you have full access to the location and file as well.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.