So i want to run the tracert command, but my problem is that the destination changes (tracert world1.runescape.com > tracert world140.runescape.com )
So my question is, how do i add the variable so it will change from 1 all the way to 140.
Try with this code :
#echo off
for /l %%# in (1,1,140) do (
echo TraceRoute for world%%#.runescape.com
echo.
Tracert world%%#.runescape.com
)
pause
And if you like to store the result into a text file :
#echo off
Color 0A & Mode con cols=80 lines=3
Set LogFile=Traceroute.txt
If Exist %LogFile% Del %LogFile%
for /l %%# in (1,1,140) do (
echo TraceRoute for world%%#.runescape.com
Cls
Title Tracert world%%#.runescape.com
echo(
echo Please Wait... TraceRoute to world%%#.runescape.com in progress...
Tracert world%%#.runescape.com >> %LogFile%
)
pause
So you are looking to keep doing tracert 140 times. This code might help but It keeps on going until you close the batch file. Good Luck!!!
tracert world140.runescape.com
call tracert.bat
When you did the code, save the batch file as tracert.bat and open it. It will keep on going untill you close the window. Enjoy and Please Like!!!
Related
i would like to see if its possible to echo to an image like you can echo to a file:
echo Hello World! >>"%cd%/test.txt
Like this:
echo (base64 code) >>"%cd%/image.jpg"
what is even wrong with this?
it creates a jpeg file but it gives me the error that it can't be opened.
(probably of its code structure)
I checked it with the base64 to image converter and there is nothing wrong.
Why doesn't it create an image?
This batch file Certutil_B64_Encoding_Files.bat can let you to drag and drop any file like a jpg or png or any file else and generate another batch file with the encoded file inside, So, when you execute it, the file will be decoded and generated to the original.
Just save this code on your notepad or on notepad++ or on any text editor as :
Certutil_B64_Encoding_Files.bat and drag and drop any file over it to be encoded
#echo off
Title Encoding files with CERTUTIL utility by Hackoo 2018
color 0A & Mode 83,3
If "%~1"=="" (
color 0C & Mode 80,3
echo(
echo You must drag and drop a file over this batch script to be encoded !
Timeout /T 5 /nobreak>nul & exit /b
)
#for /f %%i in ("certutil.exe") do if not exist "%%~$path:i" (
echo CertUtil.exe not found.
pause
exit /b
)
set "TempFile=%Temp%\Temp_b64
set "OutputFile=%~nx1_encoded%~x0"
If exist "%OutputFile%" Del "%OutputFile%" >nul 2>&1
echo(
echo Please wait a while ... Encoding "%~nx1" is in progress ...
certutil.exe -f -encode "%~1" "%TempFile%" >nul 2>&1
(
echo #echo off
echo Title My head kinda look like this
echo echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo echo and my head kinda look like this:
echo CERTUTIL -f -decode "%%~f0" "%%Temp%%\%~nx1" ^>nul 2^>^&1
echo Timeout /T 5 /nobreak^>nul
echo Start "%~n1" "%%Temp%%\%~nx1"
echo Exit
)>> "%OutputFile%"
copy "%OutputFile%" /b + "%TempFile%" /b >nul 2>&1
If exist "%TempFile%" Del "%TempFile%" >nul 2>&1
Timeout /T 2 /NoBreak>nul & exit
And here is an example that i tested with my avatar Hackoo.png
Hackoo.png_encoded.bat
#echo off
Title My head kinda look like this
echo Hello, my name is Kalesheezer, but you can call me Digi Kulamba
echo and my head kinda look like this:
CERTUTIL -f -decode "%~f0" "%Temp%\Hackoo.png" >nul 2>&1
Timeout /T 5 /nobreak>nul
Start "Hackoo" "%Temp%\Hackoo.png"
Exit
-----BEGIN CERTIFICATE-----
/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1
c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMD
BAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgW
FBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAQABAAwEiAAIRAQMRAf/E
AB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQE
AAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBka
JSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4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nTDaqAcKARyMCtO10/eQyqM9
DVyTTxFC52YIU81ViucyUswsKEDHrQl0VtmtQp3Mcs2eK3be1BijXAPGOlVbqzEU
hOwc9aklSZWs4WVwCCMeleh/DDx3q/wu8aaP4r0Cf7PqmmziaM87Txgqw7qykqR6
E157DqAs5VDruQnGe4rorF4riISRNuU1orGT11P/2Q==
-----END CERTIFICATE-----
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
certutil - Dump and display certification authority (CA) configuration information, configure Certificate Services, back up and restore CA components, verify certificates, key pairs or certificate chains.
You can use the command HEX2PNG.EXE to reconstruct a text file to an image.
Example :
smiley.txt
--------------#####--------------
-----------###.....###-----------
---------##...........##---------
-------##...............##-------
------#...................#------
-----#.....................#-----
----#...####........#####...#----
----#..####c#......####cc#..#----
---#..#####cc#....#####ccc#..#---
---#..#####cc#....#####ccc#..#---
--#...####ccc#....####cccc#...#--
--#..#cccccccc#..#ccccccccc#..#--
--#..#cccccccc#..#ccccccccc#..#--
-#...#cccccccc#..#ccccccccc#...#-
-#...##########..###########...#-
-#.............................#-
-#.............................#-
-#.............................#-
--#..#######################..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
--#..#aaaaaaaaaaaaaaaaaaaaa#..#--
---#..#aaaaaaaaaaaaaaaaaaa#..#---
---#..#aaaaaaaaaaa;;;;aaaa#..#---
----#..#aaaaaaaaa;;;;;;aa#..#----
----#...#aaaaaaa;;;;;;;;#...#----
-----#...##aaaa;;;;;;;##...#-----
------#....###;;;;;###....#------
-------##.....#####.....##-------
---------##...........##---------
-----------###.....###-----------
--------------#####--------------
To build the image you have to replace each kind of char with an hexa color and then run hex2png.exe against the smileuout.txt :
In this case
The char [c] with white [FFFFFFFF]
The char [a] with maroon [103E66FF]
The char [.] with yellow [00EAFFFF]
The char [-] with transparent (black + transparent value to 00) [00000000]
The char [#] with black (non transparent) [000000FF]
The char [;] with red [0000FFFF]
This bat will do that :
#echo off
set $fichier=smiley.txt
set $taille=33;31
set $TotPix=1023
set $Fsortie=smiley.png
:::Crátion de la première ligne de sortie.txt (width_pixel;Height_pixel;Name_of_file.PNG;Total_number_of_pixel)
echo %$taille%;%$Fsortie%;%$TotPix%>SmileyOut.txt
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type %$fichier%') do (echo %%a
set $ligne=%%a
set $ligne=!$ligne:c=FFFFFFFF !
set $ligne=!$ligne:a=103E66FF !
set $ligne=!$ligne:.=00EAFFFF !
set $ligne=!$ligne:-=00000000 !
set $ligne=!$ligne:#=000000FF !
set $ligne=!$ligne:;=0000FFFF !
set /a $c+=1
for %%b in (!$ligne!) do (echo %%b>>SmileyOut.txt))
endlocal
hex2pngV1.3.exe smileyout.txt
del smileyout2>nul
start smiley.png
The output will be this nice smiley :
The structure of the file smiley.txt is very important !
This vars must be setted correctly or the image will be corrupted :
$fichier=smiley.txt
$taille=33;31 => width;height of the output file each char is one pixel
$TotPix=1023 => The total of pixel (width * height)
$Fsortie=smiley.png => the name of the output PNG
The command PNG2HEX will do exactly the contrary an generate a txt file from an image !
im making an script to ping different websites. I want to read addresses from a file, ping them one time, and write the results on another text file.
echo off
cls
echo "TEST" > %cd%\out.txt
time >> %cd%\out.txt
ping -n 1 google.com>> %cd%\out.txt
pause>null
I dont know how to make the loop for pinging and also, how to read line by line from the file. Can anyone help me?
Thanks.
Something along the lines of the following should be what you want:
#echo off& setlocal
echo google.com>sites.txt
echo yahoo.com>>sites.txt
set cd=.
for /f %%w in (sites.txt) do call :NextSite %%w
exit /b
:NextSite
echo. >>%cd%\out.txt
echo. >>%cd%\out.txt
echo. | time | find "current" >>%cd%\out.txt
ping -n 1 %1 >>%cd%\out.txt
The logic starts at the line with the "for" statement; the preceding lines merely set up a test environment. You will have your own %cd% setting and filename to replace "sites.txt"
Actually I am very new to batch and this forum, so this is my first question here.
My goal is to create a batch-program which keeps checking if a specific IP is reachable.
As soon as it stops to be reachable / loses connection, it should open a browser and a specific website on it.
Could maybe someone help me with it? Here is, what i created so far, but it does not work very well:
#setlocal enableextensions enabledelayedexpansion
#echo off
set ipaddr=127.0.0.1
:loop
set state=down
for /f "tokens=8,10" %%a in ('ping -n 1 !ipaddr!') do (
if "x%%a"=="xLost" if "x%%b"=="x1," set state=up
(cd "C:\Program Files (x86)\Mozilla Firefox\"
start firefox.exe http://www.google.com
)
)
echo.Link is !state!
ping -n 6 127.0.0.1 >nul: 2>nul:
endlocal
unsure, what "does not work very well" means. But I suggest another way, that works independend of locale Settings and uses the default browser:
set ipaddr=www.stackoverflow.com
:Loop
ping -n 6 127.0.0.1 >nul: 2>nul:
ping -n 1 %ipaddr%|find "(0%" >nul && goto Loop
echo Connection lost
REM start the site in the Default browser:
start "" http://www.google.com
I have a list of computers that I want to make some things according to tcp connection status.
I'm trying to check tcp connection and if errorlog is "1" so write line to log and skip to next computer.
The problem is that when a computer has no tcp connection the goto skip_action command takes the script to the end and exit and the other computers in the list left unprocessed.
I have also tried to use goto :eof and it terminates the script unexpected.
ipst.txt file:
1 10.1.1.10
3 10.1.3.10
8 10.1.3.10
This is the batch file code:
#echo off
setlocal enabledelayedexpansion
set computerslist=ipst.txt
for /f "usebackq tokens=1,2" %%A in ("%Computerslist%") do (
cls
set Station_Num=%%A
set Comp_IP=%%B
ping !Comp_IP! -n 1 | findstr "TTL"
if !errorlevel!==1 (
echo Station !Station_Num! .... !Comp_IP! ..................... No Communication.>>%log%
goto skip_action
)
echo Getting Administrator Credentials:
net use \\!Comp_IP! /USER:WORKGROUP\****** ******
echo.
xcopy file.txt \\!Comp_IP!\c\temp\
echo Disconneting Session From Remote Computer :
net use \\!Comp_IP! /DELETE /YES
:skip_action
echo end of working on !Station_Num!
)
echo end of script
The problem here is that GOTO cancels the for loop.
But you can simply enclose your action in an ELSE block
for /f "usebackq tokens=1,2" %%A in ("%Computerslist%") do (
cls
set Station_Num=%%A
set Comp_IP=%%B
ping !Comp_IP! -n 1 | findstr "TTL"
if !errorlevel!==1 (
echo Station !Station_Num! .... !Comp_IP! ..................... No Communication.>>%log%
) Else (
echo Getting Administrator Credentials:
net use \\!Comp_IP! /USER:WORKGROUP\****** ******
echo.
xcopy file.txt \\!Comp_IP!\c\temp\
echo Disconneting Session From Remote Computer :
net use \\!Comp_IP! /DELETE /YES
)
echo end of working on !Station_Num!
)
General form of if - else statement
If condition (
Statements
) else (
Statements to be executed if condition is not met
)
Make your call from the loop
You can have a function ping .. and parse variable references to it .. the preceding code could also be rendered as %%a and %%b being the first and second argument respectively -- in your function call ...
Call :pingcomputers %%a %%b
This way you avoid set altogether
:pingcomputers
Rem Pinging computer %~1
Ping %~2 ¦ find "reply"
If errorlevel 1 goto failed
(Actions to be performed if ping wa successful)
Assuming that your script has a label failed and actions to.be performed if error level is not 0 ..
Not much of a script but hope it helps ...
I made a (very) simple batch file:
#echo off
:start
arp -a | findstr 20-7c-8f-3f-03-9c
cls
if %errorlevel% GEQ 1 (
echo The device is offline
Echo Device is offline at %time% on %date%. >> log.txt
) else (
echo The device is online.
Echo Device is online at %time% on %date%. >> log.txt
)
timeout 3 >nul /nobreak
goto start
While this works fine and dandy, it doesn't work if said device is not listed, ie Phones.
Here's what I mean.
All of the devices connected to my router don't show up in the arp -a output. Say the Mac address of my ipod is 18:E7:F4:86:75:9F. Is there some alternative way to detect if it is on the LAN? Or should I just other software. I like using this, and having it always running in the background. It would be an extremely useful tool. I could tell when my parents get home, or just if anybody I know is at my house. It would serve as a lazy security program. Just thinking of some ideas and potential this could have.
Am I just better off using Nmap?
I figured out a roundabout method to the issue. It doesn't necessarily solve my problem, it just makes my program work. It uses a tool called Wireless Network Watcher, and uses its command line features. I basically print everything on the programs screen to file.txt, and then I scan file.txt for the mac address. It takes around seven seconds to cycle through this whole process, but it gets the job done.
Code:
#echo off
echo gathering info . . .
:start
if exist info.txt del info.txt
wnetwatcher.exe /stext info.txt
:loop
if exist "info.txt" (
goto aaa
)
timeout 2 >nul /nobreak
goto loop
:aaa
cls
find info.txt "18-E3-A4-86-75-9C" >nul
if %errorlevel% GEQ 1 (
color c0
echo.
echo.
echo. Cole's iPod is offline.
) else (
color a0
echo.
echo.
echo. Cole's iPod is online.
)
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Refreshing (7s)
goto start
It would still be nice to have another answer, i.e., why does my ipod not show up?