IP to HostName and HostName to IP to text file script

I have faced many sitiation in my IT career  where I have to get host names from alist of IP address & sometime ipaddress to hostnames.  I have researched on internet & found two useful scripts but never got a time to share it on my blog. Today I got the same situation & I used those scripts to accomplish my task.

Below are the two scripts:-

1. Hostname to Ip address( it will take input from text file & resturn in CSV)

@echo off
set ComputerList=C:\hostname\hostname.txt

Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion

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

2.  IP address to hostnames( it will take input from text file & resturn in txt file)

@echo off

for /F %%a in (‘type c:\hostname\ip.txt’) do call :Sub %%a

goto :eof

:Sub

for /F %%b in (‘nbtstat -A %1 ^| find “<00>” ^| find /i “unique”‘) do echo %1 Hostname %%b

Thanks to the scripters that created these scripts.

Advertisements

One thought on “IP to HostName and HostName to IP to text file script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s