This is a simple script I wrote up because I think I saw someone mention they would like a way to convert an IP Address into a Hostname. I also threw in a Hostname to IP Address just because.
Code:
#NoEnv
TempDir = %A_Temp%
TrcR = 20 ; German language = 23
If A_OSVersion = WIN_2000 ; Win 95/98/2000 do not have tracert switches
TrcV =
Else If A_OSVersion = WIN_98
TrcV =
Else If A_OSVersion = WIN_95
TrcV =
Else
TrcV = -h 1
GuiMenu:
Gui, 2:Destroy
Array1 =
Array2 =
Array3 =
Array4 =
IPAdd = 0
Gui, +ToolWindow
Gui, Add, Text,, Enter the IP/Web Address or Hostname below:
Gui, Add, Edit, w150 h21 vIPHost -VScroll -Wrap, %IPHost%
Gui, Add, Button, default, Resolve
Gui, Add, Edit,, %IP1%
Gui, Add, Edit,, %Host1%
Gui, Add, Edit,, %Host2%
Gui, Show,, Resolve IP or Host
Return
ButtonResolve:
Gui, Submit
Gui, 2:+ToolWindow -SysMenu
Gui, 2:Add, Progress, vProgressV w300 h20 cBlue
Gui, Destroy
Gui, 2:Show,, Progress
IP1 =
Host1 =
Host2 =
IPHost2 = %IPHost%
StringSplit, Array, IPHost, .
If Array1 is digit
IPAdd += 1
If Array2 is digit
IPAdd += 1
If Array3 is digit
IPAdd += 1
If Array4 is digit
IPAdd += 1
GuiControl, 2:, ProgressV, +10
If IPAdd = 4
{
RunWait, cmd /C tracert %IPHost2% %TrcV% >"%TempDir%\IPHost.txt",,Hide
GuiControl, 2:, ProgressV, +30
FileRead, FRead, %TempDir%\IPHost.txt
GuiControl, 2:, ProgressV, +10
StringTrimLeft, FRead, FRead, %TrcR%
GuiControl, 2:, ProgressV, +10
StringGetPos, FReadL, FRead, %A_Space%[%IPHost2%]
GuiControl, 2:, ProgressV, +10
StringMid, FRead, FRead, %FReadL%,, L
GuiControl, 2:, ProgressV, +10
Host1 = %FRead%
IP1 = %IPHost2%
GuiControl, 2:, ProgressV, +20
GoSub, GuiMenu
Return
}
else If IPAdd <> 4
{
RunWait, cmd /C ping %IPHost2% -n 1 >"%TempDir%\IPHost.txt",,Hide
GuiControl, 2:, ProgressV, +10
FileReadLine, FRead, %TempDir%\IPHost.txt, 2
GuiControl, 2:, ProgressV, +10
StringGetPos, FReadL, FRead, [
StringGetPos, FReadR, FRead, ]
GuiControl, 2:, ProgressV, +10
FReadR := FReadR - FReadL - 1
FReadL := FReadL + 2
StringMid, FRead, FRead, %FReadL%, %FReadR%
GuiControl, 2:, ProgressV, +10
IPHost2 = %FRead%
IP1 = %FRead%
}
GuiControl, 2:, ProgressV, 50
RunWait, cmd /C tracert %IPHost2% %TrcV% >"%TempDir%\IPHost.txt",,Hide
GuiControl, 2:, ProgressV, +10
FileRead, FRead, %TempDir%\IPHost.txt
StringTrimLeft, FRead, FRead, %TrcR%
StringGetPos, FReadL, FRead, %A_Space%[%IPHost2%]
StringMid, FRead, FRead, %FReadL%,, L
GuiControl, 2:, ProgressV, +10
Host1 = %FRead%
RunWait, cmd /C tracert %IPHost% %TrcV% >"%TempDir%\IPHost.txt",,Hide
GuiControl, 2:, ProgressV, +10
FileRead, FRead, %TempDir%\IPHost.txt
StringTrimLeft, FRead, FRead, %TrcR%
StringGetPos, FReadL, FRead, %A_Space%[%IPHost2%]
StringMid, FRead, FRead, %FReadL%,, L
GuiControl, 2:, ProgressV, +10
Host2 = %FRead%
GuiControl, 2:, ProgressV, +10
GoSub, GuiMenu
Return
GuiClose:
ExitApp
This should also allow you to resolve websites to their hostname when using the IP/Web to Host option. The script should be fairly easy to customize and place in your own scripts if anyone feels the need.
There shouldn't be many things that won't resolve. I can see where it would not resolve a website that started with something that looks similar to an IP address like 123.18.28.29.hotdog.com, but this should be pretty rare.
Let me know if anyone finds this useful!
Edit: Updated code with OS checking, Progress bars, choosing correct mode of operation automatically, and a variable for the tracert switches for other languages.