A batch file to get IP location

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rafhack
Posts: 19
Joined: 23 Feb 2014 15:02

A batch file to get IP location

#1 Post by Rafhack » 05 May 2014 10:12

This code works with Vbscript and can get an IP information

Code: Select all

@echo off
setlocal enabledelayedexpansion
set /p "ip=IP: "
(
echo/Dim oXMLHTTP
echo/Dim oStream
echo/wscript.echo httpGet
echo/Function httpGet
echo/Set oXMLHTTP = CreateObject^("MSXML2.XMLHTTP.3.0"^)
echo/oXMLHTTP.Open "GET", "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=!ip!", False
echo/oXMLHTTP.Send
echo/If oXMLHTTP.Status = 200 Then
echo/   Set oStream = CreateObject^("ADODB.Stream"^)
echo/   oStream.Open
echo/   oStream.Type = 1
echo/   oStream.Write oXMLHTTP.responseBody
echo/   oStream.Position = 0
echo/    oStream.Type = 2
echo/    oStream.CharSet = "ascii"
echo/   httpGet = oStream.ReadText
echo/   oStream.Close
echo/End If
echo/End Function
) > get.vbs
for /f  "tokens=2,3"  %%a in ('cscript //nologo get.vbs') do (
set "content=%%b"
set "content=!content:~0,-1!"
echo/%%a !content!>>teste.txt)
type teste.txt|find /v /i "templa">_teste.txt
del teste.txt&ren _teste.txt teste.txt
for /f "tokens=1,2" %%a in ('type teste.txt') do (
 for /f "tokens=1,2 delims==" %%k in ('echo/%%a 2^>nul') do (
  set "_info=%%k"
  if "!_info!" == "name" (set "info=%%~l")
 )
 set "info=!info:~0,-2!"
 for /f "tokens=2* delims==" %%k in ('echo/%%b') do (
  if "!_info!" == "name" (set "info=!info! : %%~k")
 )
 echo/!info! 2>nul
)
pause > nul
del get.vbs
del teste.txt

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: A batch file to get IP location

#2 Post by siberia-man » 06 May 2014 01:02

Thereis the best (in my opinion) place to know about yourself -- ifconfig.me. I don't have any relationship with the site I am just its user.

Loook at this page as well with-love-from-siberia.blogspot.com/2012/03/universal-way-to-identify-your-external.html

Code: Select all

Dim xmlhttp, ip
 
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "GET", "http://ifconfig.me/ip", False
xmlhttp.send
 
ip = xmlhttp.responseText


You can combine the example above with the solution of embedding the vbscript code into the batch file as discussed here www.dostips.com/forum/viewtopic.php?f=3&t=5543

Post Reply