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?
Related
So i have this simple homework of doing a batch file that shows 3 options, and an error message for the entry for the option. so far it seems simple for me. I saw a youtube video and according to what i know it suppose to run ok but the problem is that when I run it and choose option 2 it opens also option 1, and when I choose option 3 it doesn't exit the program. And when I choose a parameter that is not specify the error message do not show. I am gonna copy paste my batch file because is easy to understand.
#echo off
echo Choose an option:
echo.
echo 1)Open Disk cleanup
echo 2)Open Disk Defragmenter
echo 3)Exit
echo.
Set /p Op=Write the option:
if %op%==1 (
start %windir%\system32\cleanmgr.exe
)
else if %op%==2 (
start %windir%\system32\dfrgui.exe
)
else if %op%==3 (
exit
)
else (
cls
echo Error not defined
)
pause
Is there something that I am missing or wrote wrong please let me know. If you can copy paste and run it in your computer and tell me if it is working fine because something tell me that in the process of learning I try a few times and i think I messed up with something that suppose to run correctly the file since my instructor told me that we have to be careful when using the commands in a batch file.
Your code formatted correctly but is susceptible to command injection because of the usage of the SET /P command.
#echo off
echo Choose an option:
echo.
echo 1)Open Disk cleanup
echo 2)Open Disk Defragmenter
echo 3)Exit
echo.
Set /p Op=Write the option:
if "%op%"=="1" (
start "" "%windir%\system32\cleanmgr.exe"
) else if "%op%"=="2" (
start "" "%windir%\system32\dfrgui.exe"
) else if "%op%"=="3" (
exit /b
) else (
cls
echo Error not defined
pause
)
A best practice solution which handles invalid input options.
#echo off
echo Choose an option:
echo.
echo 1)Open Disk cleanup
echo 2)Open Disk Defragmenter
echo 3)Exit
echo.
choice /C 123 /N /M "Select an Option:"
set "op=%errorlevel%"
if "%op%"=="1" start "" "%windir%\system32\cleanmgr.exe"
if "%op%"=="2" start "" "%windir%\system32\dfrgui.exe"
if "%op%"=="3" exit /b
I did it with this code.
#echo off
echo Choose an option:
echo.
echo 1)Open Disk Cleanup Utility
echo 2)Open Disk Defragmenter
echo 3)Exit
echo.
Set /p op/3=Write the number option:
if %op/3%==1 (
start %windir%\system32\cleanmgr.exe
)
if %op/3%==2 (
start %windir%\system32\dfrgui.exe
)
if %op/3%==3 (
exit
)
else (
cls
echo Error not defined
)
pause
the only problem that I have is that the error message appears even though options 1 and 2 are selected, it executes the options but it also shows the error message. I only want that the error message to show if any of those parameters aren't chosen.
I know that else is responding because if I choose option 1 else it executes because is not number 2 or 3. What it comes to my mind is if it is possible to define the op variable in an enumeration format like a group set of options.
I am trying to make a quick program in Batch that asks for user input, but when i get to the input part, the script exits with error:
The syntax of the command is incorrect.
This is my code:
#echo off
color 0a
title WinDoS/PoD- 0.1
echo Automatic DoS/PoD Tool
echo Select what you want to do.
echo 1. Attack
echo 2. Instructions
echo 3. IP Getter
echo 4. IP Searcher
echo 5. Exit
set /p userchoice=
if %userchoice% == 1
goto attack
if %userchoice% == 2
goto instructions
if %userchoice% == 3
goto getter
if %userchoice% == 4
goto searcher
if %userchoice% == 5
exit
:searcher
arp -a
pause
:attack
echo Enter IP adress to attack
set /p address=
goto sequence
:sequence
ping %address% -l 65500 -w 1 -n 1
goto sequence
:instructions
echo WinDoS/PoD Instructions
echo WinDoS/PoD is a program that allows you to perform Denial Of Service (DoS) attacks using a method known as Ping Of Death (PoD)
echo Press 1 on the home menu to enter the attacker program.
echo Input an ip address to DoS
echo If you don't know the IP address to a site, use the built in getter.
echo If you want to view all available network targets, use the built in searcher.
pause
:getter
echo Website (full link):
set /p %website%=
tracert %website%
pause
What is wrong with the syntax?
You're using the wrong command for choosing a known list item, you should be using choice, not set.
Here's an example using your provided information as its basis:
#Echo Off
Color 0A
Title WinDoS/PoD- 0.1
:Menu
Echo(
Echo Automatic DoS/PoD Tool
Echo(
Echo Home Menu
Echo(
Echo 1. Attack
Echo 2. Instructions
Echo 3. IP Getter
Echo 4. IP Searcher
Echo 5. Exit
Echo(
%__AppDir__%choice.exe /C 12345 /N /M "Select a Home Menu item number>"
If ErrorLevel 5 GoTo :EOF
If ErrorLevel 4 GoTo Searcher
If ErrorLevel 3 GoTo Getter
If ErrorLevel 2 GoTo Instructions
:Attack
ClS
Set /P "address=Enter IP address to attack> "
:Sequence
%__AppDir__%ping.exe %address% -l 65500 -w 1 -n 1
GoTo Sequence
:Instructions
ClS
Echo WinDoS/PoD Instructions
Echo(
Echo This program allows you to perform Denial Of Service (DoS) attacks,
Echo using a method known as Ping Of Death (PoD).
Echo(
Echo Press 1 on the Home Menu to begin the Attack program.
Echo Input an IP address to DoS
Echo If you don't know the IP address for a site, use the built-in Getter.
Echo If you want to view all available network targets, use the built-in Searcher.
Echo(
Pause
GoTo Menu
:Getter
ClS
Set /P "website=Website (full link)> "
%__AppDir__%tracert.exe %website%
Pause
GoTo Menu
:Searcher
ClS
%__AppDir__%arp.exe -a
Pause
GoTo Menu
Please note, that I have not looked at the usage of any of your commands, I have offered only improvements to the layout and functionality.
#echo off
set SCENARIO21=20
set WEAPON1=gun
set DOG1=buddy
set SCENARIO11=broken laptop
set ALIVE1=yes
:day51
cls
echo.
echo Player 1 %SCENARIO21% %WEAPON1% %SCENARIO11%
echo %DOG1%
echo.
echo.
echo Day 5
echo.
echo That was a close one, im glad i got that jacket off when i did...that could've ended really badly...
pause
cls
echo Dang this road seems to go on forever...
pause
cls
echo Woah...
pause
cls
echo That house looks...normal...
pause
cls
echo Is somebody in there?
pause
cls
echo Come on who would live in that house though...
pause
cls
echo Its old, worn down, the roof is bowed, the paint is peeling...
pause
cls
echo And ew...that furniture looks like something from the 2000s
pause
cls
echo Whoever lived there last must've been an old couple...really old...
pause
cls
echo Maybe there is someone in there
pause
cls
echo The windows look like they're sparkling...
pause
cls
echo Wow. Is that a...?
pause
cls
echo A um...what are those called...Oh yeah...
pause
cls
echo A plant?
pause
cls
echo No...it couldn't be
pause
cls
echo The world's last farmer died about 70 years ago...
pause
cls
echo The 2100s...
pause
cls
echo No one knows how to plant anything, let alone GROW anything anymore...
pause
cls
echo Atleast thats what i thought...
pause
cls
echo I wonder if i should go in...
pause
if %ALIVE1%==yes (
cls
echo Player 1
pause
cls
echo Player 1
echo This house gives me a strange feeling...i can't tell if it's good or bad...
echo -Yes (go in, check the house, maybe it has a planting guide...or maybe theres someone in there...and hey if there is someone, why wouldn't they help you)
echo -No (screw that, its not worth it, if you go in your gonna die, duh...anyways what could be of use in a house as old as the 2000s)
set /p SCENARIO51=Should you go in the house?
if %SCENARIO51%==yes (
cls
echo You walk into the home...
pause
cls
echo Hello?
pause
cls
echo *distant voice* Hello...why are you in my home?
pause
cls
echo Sorry sir...ma'm...um i wasn't trying to bother you...
pause
cls
echo *distant voice* You didn't answer my question...and it's sir, thank you...
pause
cls
echo Oh...i came in because i saw the plants outside...
pause
cls
echo *distant voice* And? Is that your only reason...
pause
cls
echo Well i haven't seen plants until now...i was wondering how?
pause
cls
echo *distant voice* YOU'VE NEVER SEEN PLANTS? THIS IS WHY I GO AGAINST THE SYSTEM...
pause
cls
echo What system sir?
pause
cls
echo *distant voice* If we're going to have a conversation come sit with me...walk to the end of the hall and take a left into my room...
pause
cls
echo You walked into the room of the strange voice and found an old man sitting in a chair that looked like a bubble of water being squished...
pause
cls
echo *Old Man* Im Alexander...im 170 years old...
pause
cls
echo H-h-how?
pause
cls
echo *Alexander* Okay i don't have all day i must attend to other things...I'll tell you what
echo I'll answer 1 question...any question...
pause
cls
if %SCENARIO51%==yes
echo This is your chance...
echo -1 (How did this all start?)
echo -2 (How do i get to the city of Lillian?)
echo -3 (How do i live forever just like you?)
set /p SCENARIOP51=What would you like to ask?
if %SCENARIOP51%==1 (
cls
echo *Alexander* Wow...good question...
echo It started in 2100...
pause
cls
echo When the last farmer died?
pause
cls
echo *Alexander* No, when the last farmer turned immortal...me
pause
cls
echo No i saw it on the news drone...he's dead...
pause
cls
set CODE=LSON5676
echo *Alexander* AGAIN...Sorry, that was the system's news drone...they tend to "confuse" everyone's story to make themselfs look better...
echo Anyways...in 2100 two groups of hacking experts went to war...
pause
cls
echo It ended when one of the groups found a way to literally melt the other groups computers into green radioactive goop...
echo No one really knows for sure how the war was started but most say it was because one group had a hostage...
pause
cls
echo The hostage was said to be the head hacker for the opposing group that was finding some cure...his name was Larson...
echo But for some reason when asking for Larson back the opposing group requested they send %CODE% back...
pause
cls
echo That sounds like a code...
echo better write it down...
echo %CODE%
pause
cls
echo *Alexander* It was all for some stupid reason in my opionion anyways...
echo But back to what happened...
echo After they figured out how to turn the computer into this green goop..they did it to all their computers...
echo Little did they know the goop became radioactive Artificial Intelligence...it could think on its own...
echo And it spread like wild fire...any technology it touched became more green goop...
echo Something else they didn't realize is the goop could sink into your skin with no problem at all...
echo It goes into your veins and overclocks your heart...
echo It was a nano-technology weapon...atomic level capabilities...
echo It was a devastation...
echo And thats all i know...
pause
cls
echo Thank you Alexander...this information won't go to waste...
pause
set ALIVE1=yes
)
if %SCENARIOP51%==2 (
cls
set CODE=5676
echo *Alexander* HA! thats simple...
echo you're not that far either...
echo Go down the road and take the 3rd right
echo You'll be right in front of it...
pause
cls
echo You followed his advice and fell into a trap
pause
cls
type "the end.txt"
pause
cls
set ALIVE1=no
)
if %SCENARIOP51%==3 (
cls
echo *Alexander* Come with me ill show you...
echo This guy seems kinda fishy...
echo Go (go with Alexander to find out what makes him live forever)
echo Leave (Don't follow Alexander, say you have a group waiting outside and you need to get back to them...)
)
if %SCENARIOP51%==3 (
set /p SCENARIOPP51=Do you want to follow Alexander?
)
if %SCENARIOP51%==3 (
if %SCENARIOPP51%==go (
cls
set CODE=LSON5676
echo *Alexander* you aren't smartest are you?
pause
cls
echo You turn around and...
pause
cls
echo *BANG*
pause
cls
echo You died...
pause
cls
type "the end.txt"
pause
set ALIVE1=no
)
if %SCENARIOPP51%==leave (
cls
set CODE=LSON5676
echo *Alexander* I know you're not with anyone but that dog of yours %DOG1%...
pause
cls
echo How do you know his name?
pause
cls
echo *Alexander* you called him to come as you walked down the street cause he was sniffing something...i over heard...
echo I respect your efforts to not fall into traps though...
echo Take this...
pause
cls
echo Alexander handed you a small square of yellow paper with the writing %CODE% on it...
pause
cls
echo *Alexander* take the sticky note and get out...
pause
cls
echo You take the sticky note and leave the house...
pause
cls
echo Whats a sticky note?
pause
)
)
if %SCENARIO51%==no (
cls
echo That thing gives me the creeps...
echo Bye bye house of horror...
set SCENARIO51=none
pause
set ALIVE1=yes
)
)
)
set END=0
if %ALIVE1%==no (
set /a END=%END%+1
)
if %END%==1 (
exit
)
goto day61
:day61
echo yay!
pause
exit
I've tried everything, im very new to coding hence the simple codes but im so confused on what's wrong. I've been coding this 4 player game for about 4 days and i've been stuck trying to fix this specific code. Whenever i load up the game I can get here and get through each scenario but then for instance if i chose to ask the first question I could get through all the dialogue BUT the %CODE% doesn't show up because #echo is off. Also, after completing the 1st question it will still ask me this part:
if %SCENARIOP51%==3 (
cls
echo *Alexander* Come with me ill show you...
echo This guy seems kinda fishy...
echo Go (go with Alexander to find out what makes him live forever)
echo Leave (Don't follow Alexander, say you have a group waiting outside and you need to get back to them...)
)
if %SCENARIOP51%==3 (
set /p SCENARIOPP51=Do you want to follow Alexander?
)
Even though %SCENARIOP51%==1 it still has me set /p SCENARIOPP51 even though %SCENARIOP51% doesn't equal 3. Please Help It Would Be Veryyyyyy Appreciated. Thanks! :)
if %ALIVE1%==yes (
cls
echo Player 1
pause
cls
echo Player 1
echo This house gives me a strange feeling...i can't tell if it's good or bad...
echo -Yes (go in, check the house, maybe it has a planting guide...or maybe theres someone in there...and hey if there is someone, why wouldn't they help you)
Note that this fortuitous? ) ends the if. If you want to actually show the ) here then you need to escape the ) by coding ^). The drawback though is that your if is then not closed for a large number of lines (I'm not going to look through all that code) - and your if %SCENARIO51% opens (another) nested code-block.
Within a code-block (a parenthesised sequence of lines) any %var% is replaced by the value of that variable when the instruction controlling the block (if, for) is encountered. Hence, your set/p which varies SCENARIO51 will appear to use the previous value of SCENARIO51 for %SCENARIO51% within the block.
You need to look at delayedexpansion - hundreds of SO articles about that.
And also be warned : replying Enter alone to a set/p will leave the variable unchanged.
Since you are using set/p you should also use the format
if "%varname%"=="targetstring" ...
in order to have some immunity to empty/separator-containing strings.
Further, the /i switch applied to if will make the comparison case-insensitive.
And it may benefit you to learn batch subroutines. See call /? from the prompt for documentation.
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!!!
Whenever i run the .bat file it all goes well i choose my time it says it in minutes and all until it comes to confirming your decision and i really have no clue how to fix it for some reason it just goes to :shutdown
Intention: I am using this as a simple little tool when installing games for example if i have to leave steam to download and install a large game overnight i just choose a time and leave it :)
Note: I have no experience with coding ( except changing values on LUA scripts in games ) so an explanation would be
Greatly Appreciated and yes sure i can just use the shutdown command but i wanted to create something a little more fancy
Also if someone could explain to me what the
/s in shutdown
and /a in set timedelay commands do because as i stated i have little to no experience
.
If you can't answer or can't be bothered thank you for your time either way!
Thank you in advance! :)
.
#echo off
cls
title Delayed Shutdown
echo Delayed Shutdown by Martin Angelov
echo Press Any Key To Choose Delay
Pause>NUL
:choosedelay
cls
echo Type in the desired ammount of delay
set /p timedelaysec=
set /a timedelaymin=%timedelaysec% / 60
:confirmation
echo Your current desired shutdown time is:
echo %timedelaysec% Seconds
echo ( %timedelaymin% Minutes )
echo Press 1 to Confirm Shutdown
echo Press 2 to Change Delay
echo press 3 to Exit Program
set /p confirmaation =
if "%confirmaation%" == "1" goto shutdown
if "%confirmaation%" == "2" goto choosedelay
if "%confirmaation%" == "3" goto exit
:shutdown
cls
echo Shutting Down!
echo Delay Chosen:
echo %timedelaysec% Seconds
echo ( %timedelaymin% Minutes )
pause
exit
:exit
cls
echo Exiting Program...
ping 0.0.0.0 -n 2
exit
:Temporary so it doesn't actually enable the shutdown
shutdown /s /t %timedelaysec%
In batch files, it's usually something simple and frustrating.
Try
set /p confirmaation=
(Note that I removed a space before the equals.)
If that fixes your problems, your environment variable wasn't set to any of the three values you checked for and the logic very naturally went line-by-line to :shutdown.
Good luck!