String from file, how to set it as a Variable?
Moderator: DosItHelp
String from file, how to set it as a Variable?
Greetings!
Anyone who can salve this ?
How to set specific word in string to a variabel and
later on echo it?
#Batch.bat
echo Ipconfigurations to file.
ipconfig > File.txt
#File.txt
Text .......
#Call Batch2.bat from Command prompt
type File.txt | findstr exactly "192"
:: set selected string to variabel.
:: Here is my problem! How can i set only 1
:: word from a specific string e.g. "192.168.1.20"
echo Your ip is: %ip%
192.168.1.20
pause
Anyone who can salve this ?
How to set specific word in string to a variabel and
later on echo it?
#Batch.bat
echo Ipconfigurations to file.
ipconfig > File.txt
#File.txt
Text .......
#Call Batch2.bat from Command prompt
type File.txt | findstr exactly "192"
:: set selected string to variabel.
:: Here is my problem! How can i set only 1
:: word from a specific string e.g. "192.168.1.20"
echo Your ip is: %ip%
192.168.1.20
pause
Re: String from file, how to set it as a Variable?
Do you want to find your LAN IP address?
Re: String from file, how to set it as a Variable?
This is a neat trick that we recently learned about the PING command. If you don't specify an IP address to PING it just ping's your own IP address. You should still specify if you want IPv4 or IPv6 on Windows Vista and 7 machines.
Code: Select all
FOR /F "tokens=3 delims=: " %%G in ('ping -n 1 "" ^|find "Reply from" ') do set myip=%%G
Re: String from file, how to set it as a Variable?
If you want to specify you can:
Code: Select all
for /f "tokens=2 delims=[]" %%f in ('ping -4 -n 1 www.DosTips.com ^|find /i "pinging"') do SET RemoteIp=%%f
echo Remote IP Address is: %RemoteIp%
Re: String from file, how to set it as a Variable?
Sweet!
Yes as Local IP
External IP if you know how to also hehe
Yes as Local IP
External IP if you know how to also hehe
Re: String from file, how to set it as a Variable?
Saitto wrote:External IP if you know how to also hehe
Are you referring to the IP address of your Router that connects to the Internet?
Re: String from file, how to set it as a Variable?
http://myip.dnsomatic.com/ is a page that only contains your plain external IP address (without any html tags etc.). For that reason it loads very fast and it can be processed very easily using a hybrid script.
Regards
aGerman
Code: Select all
@if (@X)==(@Y) @end /* valid line in Batch and JScript
:: Batch Part:
@echo off &setlocal
for /f %%i in ('cscript //nologo //e:jscript "%~fs0"') do echo %%i
pause
exit /b
:: JScript Part: */
try {
var objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
objXMLHTTP.open("GET", "http://myip.dnsomatic.com/", false);
objXMLHTTP.send();
if (objXMLHTTP.readyState == 4 && objXMLHTTP.status == 200) {
WScript.StdOut.WriteLine(objXMLHTTP.responseText);
WScript.Quit(0);
}
else {
WScript.StdErr.WriteLine("Unable to finish request or page not found.");
WScript.Quit(1);
}
}
catch (e) {
WScript.StdErr.WriteLine(e.name + ": " + e.message);
WScript.Quit(1);
}
Regards
aGerman
Re: String from file, how to set it as a Variable?
foxidrive also did a script for external ip on here: viewtopic.php?p=18333
Code: Select all
@echo off
:: ### IP ISP ADDRESS:
>>"%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 Address: %IP:~1%
pause>nul
Last edited by Xboxer on 02 Dec 2014 05:36, edited 1 time in total.
Re: String from file, how to set it as a Variable?
<?PHP
$html = file_get_contents('http://www.tibia.com/community/?subtopic=characters&name=Antizo');
$getvocation = strpos($html, 'Vocation:');
$findend = strpos($html, '</tr>', $getvocation);
$findstring = substr($html, $getvocation, $findend-$getvocation);
$vocation = str_replace('Vocation:','', $findstring);
$vocation = strip_tags($vocation);
echo $findstring;
this one works also
$html = file_get_contents('http://www.tibia.com/community/?subtopic=characters&name=Antizo');
$getvocation = strpos($html, 'Vocation:');
$findend = strpos($html, '</tr>', $getvocation);
$findstring = substr($html, $getvocation, $findend-$getvocation);
$vocation = str_replace('Vocation:','', $findstring);
$vocation = strip_tags($vocation);
echo $findstring;
this one works also

Re: String from file, how to set it as a Variable?
Saitto wrote:<?PHP
$html = file_get_contents('http://www.tibia.com/community/?subtopic=characters&name=Antizo');
$getvocation = strpos($html, 'Vocation:');
$findend = strpos($html, '</tr>', $getvocation);
$findstring = substr($html, $getvocation, $findend-$getvocation);
$vocation = str_replace('Vocation:','', $findstring);
$vocation = strip_tags($vocation);
echo $findstring;
this one works also
How do you launch that with a batch file?
Re: String from file, how to set it as a Variable?
Post above was Javascript..
Re: String from file, how to set it as a Variable?
You could always use PowerShell
Code: Select all
@Echo Off & SetLocal
For /F %%A In ('PowerShell -C^
"(Invoke-WebRequest http://ipinfo.io/ip).Content.Trim()"') Do Set PubIP=%%A
Echo( %PubIP%
>Nul Timeout 5
Re: String from file, how to set it as a Variable?
Code: Select all
for /F "tokens=2 delims= " %%G in ('nslookup myip.opendns.com resolver1.opendns.com') do set externalip=%%G
Re: String from file, how to set it as a Variable?
Saitto wrote:Post above was Javascript..
How do we execute that code?