I have a really bad script ( I know there are much easier ways to achieve this, but oh well.) that calculates your ip address. It uses a very complicated and slow round-about method, but I am stuck. I basically have this: A colossal txt file on my desktop with an IP address embedded into it.
Here's the code:
@if (@CodeSection == @Batch) @then
@echo off
rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"
cd\
cd users\%username%\desktop\
if exist "what is my ip address - Google Search.htm" del "what is my ip address - Google Search.htm"
if exist ip.txt del ip.txt
:: this link is just a shortened url to a google search of "what is my ip address"
start http://goo.gl/L66owU
timeout 10 >nul /nobreak
%sendkeys% "(^s)"
timeout 1 >nul /nobreak
%sendkeys% "{enter}"
timeout 5 >nul /nobreak
rename "what is my ip address - Google Search.htm" "ip.txt"
findstr /c "Your public IP address is <em>.............</em>" ip.txt
pause
goto :EOF
@end
// JScript section
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));
I cringe when looking at it.
Anyway, my bug is in this line findstr /c "Your public IP address is <em>.............</em>" ip.txt
I need to filter out everything, and get whatever value is set as the wildcards (the .......
s)
If you try out the script, you will basically have your default browser open up a google page, and then it will save that page as an HTM file (if you use chrome at least), and I then rename the .html
to .txt
. I just need a better (and working) method of displaying the IP address in the end.
I know its possible, I'm just not very good with the find
or findstr
commands.