Skip to content

Instantly share code, notes, and snippets.

@C0nw0nk
Created November 14, 2022 07:11
Show Gist options
  • Save C0nw0nk/e9143bce8e9306b5057ef6c7c9843c37 to your computer and use it in GitHub Desktop.
Save C0nw0nk/e9143bce8e9306b5057ef6c7c9843c37 to your computer and use it in GitHub Desktop.
batch file to get public facing ip address without any external files or help
@if (@This==@IsBatch) @then
@echo off & setLocal EnableDelayedExpansion & CHCP 65001 >NUL
:: Copyright Conor McKnight
:: https://github.com/C0nw0nk/
:: https://www.facebook.com/C0nw0nk
:: Execute Javascript without needing to install anything
:: store javascript output in batch file variable
set site="https://checkip.amazonaws.com/"
for /f "tokens=*" %%a in ('
cscript //nologo //E:JScript ^"%~dpnx0^"^ %site%
') do set "javascript_output=!javascript_output!%%a"
echo !javascript_output!
pause
exit /b
@end
//Javascript
// Instantiate the needed component to make url queries
var http = WScript.CreateObject('MSXML2.ServerXMLHTTP.6.0');
// Retrieve the url parameter
var url = WScript.Arguments.Item(0)
//Make the request
http.open("GET", url, false);
http.send();
//If we get a OK from server (status 200), output to console
if (http.status === 200) WScript.Echo(http.responseText);
//Close script
WScript.Quit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment