Solved Obtain IP Address Help

July 15, 2012 at 17:12:47
Specs: Windows 7
Hi, I am trying to make an advanced website blocker. Here is how it works:

User input - Website URL
User input - Confirms URL
Blocks Website with IP+URL
User input - Test if URL was blocked
User input - Would you like to block another site?

@echo off
title Website Blocker (C)xXxPANCAKESxXx
set /p url= Please type in the Website URL you would like to block: 
if %url%== %url% goto :url
set /p block= Are you sure you want to block "%url%"? Answer "Yes" or "No": 
if '%block%'== 'Yes' goto yes
if '%block%'== 'yes' goto yes
if '%block%'== 'No' goto no
if '%Block%'== 'no' goto no
cd "C:\Windows\System32\Drivers\etc"
echo %url% >> "Hosts"
echo %url% >> "Hosts"
echo Done.
set /p test= Would you like to test to see if the webpage was blocked? Answer "Yes" or "No": 
if '%test%'== 'Yes' goto test
if '%test%'== 'yes' goto test
if '%test%'== 'No' goto cancel
if '%test%'== 'no' goto cancel
start %url%
set /p done= Would you like to block another website? Answer "Yes" or "No": 
if '%done%'== 'Yes' goto no
if '%done%'== 'yes' goto no
if '%done%'== 'No' goto done
if '%done%'== 'no' goto done

See More: Obtain IP Address Help

Report •

July 15, 2012 at 20:15:24
✔ Best Answer
Are you wanting to convert the url to the ip, is that the problem? My hosts just uses for all of them. If you really want the ip, old versions of "ping" can supply it, and there's prob'ly other better ways to get it that I'm unaware of.
Aside from that, I'm not sure about other things in your script:
What does this do?
if %url%== %url%

And why do you put it into hosts twice?
cd "C:\Windows\System32\Drivers\etc"
echo %url% >> "Hosts"
echo %url% >> "Hosts"

I would advise putting:
set url=
beneath the label :no, to clear it, otherwise set /p will retain old values.
(set /p has nasty habit of retention: anytime user hits [ENTER] key, the variable
retaiins its original value, not "", so I recommend clearing the target variable prior to all set/p statements. this has driven me nuts more than once.)
You can avoid those laborious case-alternative IFs using if /i:
if /i '%done%' equ 'yes' goto :no
(see: if /?) this covers all bases: Yes, yEs, yES, yes... you get the idea.
caveat: most of this applies only if command extensions are ON, and I see no reason in the entire universe for them to be OFF unless you're running pre-XP windows, (then they're always off because they're not supported).

Report •

July 16, 2012 at 09:29:59
I think I found the solution. Testing it now...

Thank you!

Report •

Related Solutions

Ask Question