batch find external ipaddress
Moderator: DosItHelp
batch find external ipaddress
I know If you go to a website like Ipchicken you can get your external IPaddress. can you send the contents of a website like IPchicken to a file with bach? For example: If I open explorer with start In batch and have It goto IPChicken I just want to copy my External IP to a Txt or bat file. All I want It to have a batch file tell me external Ipaddress.
Re: batch find external ipaddress
You can use a 3rd party utility like WGET and point it at this website: http://automation.whatismyip.com/n09230945.asp
Re: batch find external ipaddress
I think there was a topic like that here i don't remember exactly, but you will need to use a vbscript, batch won't help:
It get the IP from http://checkip.dyndns.org
This is a modified code from the original it will give you a txt file called IP.txt Contain your External IP "Remember it's a VBscript"
You can compine this code in abatch file that make the vbscript code then run it and extract the ip and pop it up in a box with OK botten using
I use it like that some times
It get the IP from http://checkip.dyndns.org
This is a modified code from the original it will give you a txt file called IP.txt Contain your External IP "Remember it's a VBscript"
Code: Select all
Const ForReading = 1
Const ForAppending = 8
Dim ipLog, objHTTP, strHTML, varStart
Dim varStop, strIP, strCurrIP, objFSO
Dim txtFile, strLine, objShell
' Log for tracking external IP addresses
ipLog = "IP.txt"
' Get current external IP address from web
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
objHTTP.Send()
strHTML = objHTTP.ResponseText
' Extarct IP from HTML if HTML was recieved
If strHTML <> "" Then
varStart = InStr(1, strHTML, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTML, "</body>", vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTML, varStart, varStop - varStart)
Else
strIP = "Unavailable"
End If
' Remove preceeding or trailing spaces
strCurrIP = Trim(strIP)
' Check for log file and last log entry
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(ipLog)) Then
' If log file doesn't exist create it
Set txtFile = objFSO.CreateTextFile(ipLog, True)
strIP = ""
Else
' Get last external IP address entry from log file
Set txtFile = objFSO.OpenTextFile(ipLog, ForReading)
Do Until txtFile.AtEndOfStream
strLine = txtFile.ReadLine
If Len(strLine) > 0 Then
strIP = strLine
End If
Loop
End If
txtFile.Close
' Extarct last external IP from log file entry
If strIP <> "" Then
varStart = 1
varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
If varStop Then strIP = Mid(strIP, varStart, varStop - varStart)
' Remove preceeding or trailing spaces
Trim(strIP)
Else
strIP = "Unavailable"
End If
' Check if external IP has changed
If strCurrIP = strIP Then
Else
' If changed log to file and display IP
Set txtFile = objFSO.OpenTextFile(ipLog, ForAppending)
txtFile.Write(strCurrIP)
txtFile.Close
End If
' Clear variables
Set ipLog = Nothing
Set objHTTP = Nothing
Set strHTML = Nothing
Set varStart = Nothing
Set varStop = Nothing
Set strIP = Nothing
Set strCurrIP = Nothing
Set objFSO = Nothing
Set txtFile = Nothing
Set strLine = Nothing
Set objShell = Nothing
You can compine this code in abatch file that make the vbscript code then run it and extract the ip and pop it up in a box with OK botten using
Code: Select all
MSG * %ip%
I use it like that some times
Re: batch find external ipaddress
abc0502 wrote:I think there was a topic like that here i don't remember exactly, but you will need to use a vbscript, batch won't help:
It get the IP from http://checkip.dyndns.org
This is a modified code from the original it will give you a txt file called IP.txt Contain your External IP "Remember it's a VBscript"Code: Select all
Const ForReading = 1
Const ForAppending = 8
Dim ipLog, objHTTP, strHTML, varStart
Dim varStop, strIP, strCurrIP, objFSO
Dim txtFile, strLine, objShell
' Log for tracking external IP addresses
ipLog = "IP.txt"
' Get current external IP address from web
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
objHTTP.Send()
strHTML = objHTTP.ResponseText
' Extarct IP from HTML if HTML was recieved
If strHTML <> "" Then
varStart = InStr(1, strHTML, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTML, "</body>", vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTML, varStart, varStop - varStart)
Else
strIP = "Unavailable"
End If
' Remove preceeding or trailing spaces
strCurrIP = Trim(strIP)
' Check for log file and last log entry
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not (objFSO.FileExists(ipLog)) Then
' If log file doesn't exist create it
Set txtFile = objFSO.CreateTextFile(ipLog, True)
strIP = ""
Else
' Get last external IP address entry from log file
Set txtFile = objFSO.OpenTextFile(ipLog, ForReading)
Do Until txtFile.AtEndOfStream
strLine = txtFile.ReadLine
If Len(strLine) > 0 Then
strIP = strLine
End If
Loop
End If
txtFile.Close
' Extarct last external IP from log file entry
If strIP <> "" Then
varStart = 1
varStop = InStr(varStart, strIP, ",", vbTextCompare) - 1
If varStop Then strIP = Mid(strIP, varStart, varStop - varStart)
' Remove preceeding or trailing spaces
Trim(strIP)
Else
strIP = "Unavailable"
End If
' Check if external IP has changed
If strCurrIP = strIP Then
Else
' If changed log to file and display IP
Set txtFile = objFSO.OpenTextFile(ipLog, ForAppending)
txtFile.Write(strCurrIP)
txtFile.Close
End If
' Clear variables
Set ipLog = Nothing
Set objHTTP = Nothing
Set strHTML = Nothing
Set varStart = Nothing
Set varStop = Nothing
Set strIP = Nothing
Set strCurrIP = Nothing
Set objFSO = Nothing
Set txtFile = Nothing
Set strLine = Nothing
Set objShell = Nothing
You can compine this code in abatch file that make the vbscript code then run it and extract the ip and pop it up in a box with OK botten usingCode: Select all
MSG * %ip%
I use it like that some times
I don't know VBscript yet. I am just learning Batch files. I don't have VB yet. So I would not know how to run It.
Re: batch find external ipaddress
Open up notepad just like you would to make a batch file. Copy and paste the code he gave you into notepad and save the file as myscript.vbs
Close notepad and double click the vbscript file you just created.
Close notepad and double click the vbscript file you just created.
Re: batch find external ipaddress
Just save it as a text file with extension .VBS and run it at the command line. Note that this is VBScript (which comes with Windows), not VB (which sells separately).Billd59 wrote:I don't know VBscript yet. I am just learning Batch files. I don't have VB yet. So I would not know how to run It.
Don't know that what you are asking for is possible using just batch and the builtin commands. As suggested above, instead of VBS you could also use something like WGET (for example the one from http://gnuwin32.sourceforge.net/packages/wget.htm) or CURL (http://curl.haxx.se/download.html).
Here is a snippet using the latter. Make sure to mind the warning on the first line. To suppress the verbose CURL output and see just the IP echo line, run with 2>nul.
Code: Select all
:: do *NOT* run more often than once every 5 minutes
:: see http://www.whatismyip.com/faq/automation.asp
@echo off
setlocal disableDelayedExpansion
set "wip="
for /f "delims=" %%a in ('curl http://automation.whatismyip.com/n09230945.asp') do set "wip=%%a"
echo public IP = %wip%
Liviu
Re: batch find external ipaddress
FWIW a different approach, simpler but only suitable for static locations (like one's home network), is to register a (free) name with dyndns.org, then ping the name and extract the (public) IP from the command output.
Liviu
Liviu
Re: batch find external ipaddress
Liviu wrote:FWIW a different approach, simpler but only suitable for static locations (like one's home network), is to register a (free) name with dyndns.org, then ping the name and extract the (public) IP from the command output.
Liviu
Good idea! Not sure why I did't think of that. I use NO-IP for my network.
Re: batch find external ipaddress
Dyndns works even more smoothly if you happen to have a router or modem with a builtin DDNS updater, in which case there is no separate client side utility required to run in the background. Don't know whether/how it will work once ISPs start dispatching IPv6 addresses, but for home users that's probably still a few good years away. And, by that time, any batch code relying on the IPv4 syntax would have to be revisited, anyway
Liviu
Liviu
Re: batch find external ipaddress
Yep. My SonicWall router supports No-Ip. So I am good to go.
Re: batch find external ipaddress
This was mentioned in the past which I took note of:
Save this as ip.php on your web site and if it supports PHP then it will give you your IP address in a plain webpage.
You can then use the following code to get your IP address in a variable (untested as my webhost is down atm)
Replace server.domain.com with your webhost URL
You will need to install Wget for windows.
Save this as ip.php on your web site and if it supports PHP then it will give you your IP address in a plain webpage.
<? print $_SERVER['REMOTE_ADDR']; ?>
You can then use the following code to get your IP address in a variable (untested as my webhost is down atm)
Replace server.domain.com with your webhost URL
You will need to install Wget for windows.
Code: Select all
@echo off
echo Finding your external IP address... please wait
cd /d %temp%.\
del "ip.txt" 2>nul
set "ip="
"c:\Program Files\WGET\WGET.EXE" -q -O ip.txt http://server.domain.com/ip.php
for /f %%a in (ip.txt) do if not defined ip set ip=%%a
echo Your external IP address is %IP%
echo.
pause
Re: batch find external ipaddress
Liviu wrote:Just save it as a text file with extension .VBS and run it at the command line. Note that this is VBScript (which comes with Windows), not VB (which sells separately).Billd59 wrote:I don't know VBscript yet. I am just learning Batch files. I don't have VB yet. So I would not know how to run It.
Don't know that what you are asking for is possible using just batch and the builtin commands. As suggested above, instead of VBS you could also use something like WGET (for example the one from http://gnuwin32.sourceforge.net/packages/wget.htm) or CURL (http://curl.haxx.se/download.html).
Here is a snippet using the latter. Make sure to mind the warning on the first line. To suppress the verbose CURL output and see just the IP echo line, run with 2>nul.Code: Select all
:: do *NOT* run more often than once every 5 minutes
:: see http://www.whatismyip.com/faq/automation.asp
@echo off
setlocal disableDelayedExpansion
set "wip="
for /f "delims=" %%a in ('curl http://automation.whatismyip.com/n09230945.asp') do set "wip=%%a"
echo public IP = %wip%
Liviu
I will try this. Do I just copy the above and paste It to notepad with the.VBS at the end? I am trying to learn VBScript too. I just started learning.I am handicapp so It takes awhile for me to learn.
Re: batch find external ipaddress
Bill? Is that you?
And no, that is a batch file that you quoted and not VBscript. It uses a tool called Curl that you will have to download.
I have another solution which involves telnet and connecting to my router and getting the WAN IP address that way.
The drawback is that it too needs a third party tool, in this case to script the Telnet session, as well as a router/modem that supports telnet.
And no, that is a batch file that you quoted and not VBscript. It uses a tool called Curl that you will have to download.
I have another solution which involves telnet and connecting to my router and getting the WAN IP address that way.
The drawback is that it too needs a third party tool, in this case to script the Telnet session, as well as a router/modem that supports telnet.
Re: batch find external ipaddress
I missed earlier posts in this thread.
Here's a simplification of the VBS solution wrapped in a batch file. It works here.
Here's a simplification of the VBS solution wrapped in a batch file. It works here.
@echo off
>"%temp%\ip.vbs" echo Set objHTTP = CreateObject("MSXML2.XMLHTTP")
>>"%temp%\ip.vbs" echo Call objHTTP.Open("GET", "http://checkip.dyndns.org", False)
>>"%temp%\ip.vbs" echo objHTTP.Send()
>>"%temp%\ip.vbs" echo strHTML = objHTTP.ResponseText
>>"%temp%\ip.vbs" echo wscript.echo strHTML
for /f "tokens=7 delims=:<" %%a in ('cscript /nologo "%temp%\ip.vbs"') do set ip=%%a
echo %ip:~1%
pause