-3

Im looking for a script (batch, perl, vb or whatever) that will resolve the hostnames i will give to it into IPS and output a file(optionally) with them, just as the Windows Hosts File.

So for example, when i give to it: www.stackoverflow.com

it will output to a file (or even in screen, with echo) this line:

69.59.197.21 www.stackoverflow.com

Thanks in advance! Happy new Year! Cheers

user1948608
  • 1
  • 1
  • 1
  • in linux u can just try this :> host www.stackoverflow.com | grep "has" – Akhil Thayyil Jan 04 '13 at 12:59
  • thanks, but this will output "www.stackoverflow.com has the address 69.59.197.21". any way to get an output of "69.59.197.21 is the address of www.stackoverflow.com" so i can mass remove "is the address of" and use it as hosts file on windows? – user1948608 Jan 04 '13 at 13:17

2 Answers2

1

Here you go

@echo off
setlocal enabledelayedexpansion
set /p hostname=Enter hostname: 
for /f "tokens=3" %%a in ('ping %hostname% ^| find "Pinging"') do (
set ip=%%a
set ip=!ip:[=!
set ip=!ip:]=!
echo !ip! %hostname%
)
pause >nul
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • Thank you Bali C! I noticed that many websites use subdomains on different ip. Is there a way to browse to the sites by browser and export the dns cache in proper for the hosts file format? I tried ipconfig /displaydns >C:\test.txt which works fine, but the output is not proper for hosts – user1948608 Jan 04 '13 at 13:46
  • Sorry, I don't get that second part. So is there a particular part of `ipconfig /displaydns` that you want to extract? – Bali C Jan 04 '13 at 14:35
  • Also, @user1948608 if you liked Bali's answer it would help him out if you clicked the check next to it and gave him credit for it! Thanks! – iesou Jan 04 '13 at 15:37
0

You can try this in linux

**print address and hostname**

    [user@server scripts]$ host www.stackoverflow.com | grep "has add" | awk '{print $1}{print $4}' 
    stackoverflow.com
    69.59.197.21

**Print address only**

    [user@server scripts]$ host www.stackoverflow.com | grep "has add" | awk '{print $4}' 
    69.59.197.21


**Append To File**

    [user@server scripts]$ host www.stackoverflow.com | grep "has add" | awk '{print $4}' >> hosts.list

Hope this helps ( in *nix )

Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48