-4

Hello everyone I am just finished writting a 1800+ lined code batch file... What it does is it blocks website and unblocks them. Now the features are the you can enter a website and block it and the you can block a whole bunch aswell. Now you can tyoe in the websites name and it will unblock or you can unblock them all uy deleting to file. Now there is a new feature... Redirection, I successfully made that prossible with you guys :). Now what this does it , you have 2 options make a website redirect to another website or redirect to the "Unable to connect page". Yes that is why I asked you guys about how to extract the IP address when you ping a website and then my progrm stores the IP address in a varible. SO you would type a website in e.g. www.facebook.com and it would ping the website and get the IP addess and store it in a varible. But this is a problem when entering a website to unblock. So I use the findstr command to look for the blocked website and remove it but this is a multiuniverse hasale. It would unblock the website the have to redirected IP address in it.

173.252.110.27 www.facebook.com www.google.co.za 
173.252.110.27 www.facebook.com www.youtube.com 

and when it redirects to the "Unable to connect page" (localhost) it would be like this...

127.0.0.1 www.miniclip.com.

Now this is my problem CMD doesnt know which is the blocked website and which is to redirect website. So I need someone to help me with a little code and yes once this is done I promise to give you a link so you can download this program that took me about 173 hours to make because I had to do alot and alot of brainstorming and thinking not just typeing code from the top of my head. Now here is the code I'm stuck with...

if %directstate% == uilocalhost (
findstr /i %IPaddress% %%A >>%hosts% 
)

if %directstate% == uiwebsite (
findstr /i %IPaddress% %directmode% %%A >>%hosts%
)

directstate varible is the varible that is the option to redirect to a website or localhost

and if the directstate varible is set on a website the Ipaddress varible is set on the extracted ping IP address and if the directstate is on localhost the IP address is set on 127.0.0.1 and the hosts varible is where the dir of the hosts file is setting.

Here is the entire code to unblock a website...

::Uninstall Selected Bocked Website START
:unblockselectedloadmenu
echo [%time%] [UNBLOCK SELECTED MENU STATUS: LOADED MENU] >>%logdir%\WEBMATRIXLOG.log
:unblockselected
set unblockURL=unblockURL
mode 52,22
echo -UNBLOCK SELECTED
echo                  ----MY PROGRAM----
echo.
echo Listing Blocked Addresses...
type %hosts%
echo.
echo b/back
echo Enter the website to unblock:
set /p unblockURL=www.
if %unblockURL% == unblockURL (goto unblockselected ) else if %unblockURL% == b (
echo [%time%] [UNINSTALL SELECTED MENU STATUS: USER BACKED OUT FROM UNINSTALL SELECTED MENU] >>%logdir%\WEBMATRIXLOG.log
goto mainmenu ) else (
echo [%time%] [UNINSTALL SELECTED MENU STATUS: INPUT WEBSITE ADDRESS: www.%unblockURL%] >>%logdir%\WEBMATRIXLOG.log )
echo.
echo Processing...
findstr /i "%unblockURL%" %hosts% >nul
IF %ERRORLEVEL% NEQ 0 (
echo Address is already uninstalled...
ping localhost -n 3 >nul
echo [%time%] [UNINSTALL SELECTED MENU STATUS: ADDRESS IS ALREADY UNINSTALLED] >>%logdir%\WEBMATRIXLOG.log
goto mainmenu )
attrib -r %hosts%
FOR %%A IN (
www.%unblockURL%
) DO (
MOVE %hosts% hosts.bak >NUL
FINDSTR /V /C:"%%A" hosts.bak > %hosts%
DEL /F /Q hosts.bak )
attrib +r %hosts%
echo DONE! - Cleared Selected Blocked Address!
ping localhost -n 2 >nul
echo You may need to restart browser
ping localhost -n 3 >nul
echo [%time%] [UNINSTALL SELECTED MENU STATUS: REMOVED WEBSITE ADDRESS: www.%unblockURL%] >>%logdir%\WEBMATRIXLOG.log
cls 
goto mainmenu
::Uninstall Selected Bocked Website END

Please help me if you understand what I am talking about. Thanks you everyone to make this possible. Remember you will get a copy of this program once it's done. Probably in a few days :)

4

1 回答 1

2

我怀疑这条线:

findstr /i %IPaddress% %directmode% %%A >>%hosts%

这将找到任何包含%IPaddress% OR %directmode%的行。从您的评论not just the ones on the left hand side中,我得出结论,您想找到包含字面意思“%IPaddress% %directmode%”的行 - 它们之间有空格。

尝试

findstr /i /c:"%IPaddress% %directmode%" %%A >>%hosts%
于 2013-03-19T23:24:57.517 回答