• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 927
  • Last Modified:

Question for SteveGTR

Hey Steve, a few years ago you worked up a script for me for adds a list of IP addresses into the trusted sites for IE

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_22837839.html

I am wondering if that script can be modified or re-written once again to include the use of domains or URLs as well as IP addresses. We have virtualized a lot of our web servers and so the IP addresses can change and have changed a number of times in this last year alone. So the need to add the URL into the trusted sites list has become very necessary. I have tried to think of a way to do it, but think I ought to post this and see if it will even be possible. The domain side of the world is a lot different, and I'm having trouble wrapping my head around it. But basically I would like it to do the same thing with domain names that the other script does with IP addresses. And if it can be combined into one script doing both IPs and URLs or domain name, that would be even better.

I hope this all makes sense.

Thanks again.
RBennett
0
Ryan Bennett
Asked:
Ryan Bennett
  • 7
  • 4
1 Solution
 
AmazingTechCommented:
Give this a go.

Add to your file the domain or URL. URL being HTTP:// or HTTPS://
@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set fileName=ipList.txt

if not "%~1"=="" set fileName=%~1

if not exist "%fileName%" echo %fileName% does not exist&goto :EOF

for /f "tokens=*" %%a in ('type "%fileName%"') do call :PROCESS "%%a"

goto :EOF

:PROCESS

set ipAddr=%~1
set basekey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap

echo Processing %ipAddr%

echo %ipAddr% | findstr "[a-z]"
if errorlevel 1 GOTO IPRANGE

echo %ipAddr% is a domain or url
Set Left=
Set Right=
Set Type=
CALL :SPLIT %ipaddr:.=%
GOTO :EOF


:SPLIT
if "%3" == "" (
    Set Right=%1.%2
    if defined Left Set Left=\%Left:~1%
) Else (
    Set Left=!Left!.%1
    ECHO !Left! | findstr /i "HTTPS://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTPS & Set Left=!Left:HTTPS://=!
    ECHO !Left! | findstr /i "HTTP://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTP & Set Left=!Left:HTTP://=!
    shift
    if "%1" NEQ "" GOTO SPLIT
)

    
IF NOT DEFINED Type (
    ECHO Domain
    Set Type=*
) ELSE (
    ECHO URL
)

REG ADD "%basekey%\Domains\%Right%%Left%" /v !Type! /t REG_DWORD /f /d 0x2
GOTO :EOF

:IPRANGE

echo %ipaddr% is an IP Range
for /f "tokens=*" %%a in ('reg query "%basekey%\Ranges" 2^>^&1 ^| findstr /i "%basekey%\Ranges\Range" 2^>^&1') do (
  for /f %%b in ('reg query "%%a" 2^>^&1 ^| findstr "%ipAddr%"') do reg delete "%%a" /f >NUL
)

set /a cnt=0

:NEXTRANGE

set /a cnt+=1

set key=%basekey%\Ranges\Range%cnt%

for /f %%a in ('reg query "%key%" 2^>^&1 ^| findstr /i /c:ERROR:') do goto GOTRANGE

goto NEXTRANGE

:GOTRANGE

reg ADD "%key%" >NUL

echo Adding Range%cnt%

reg ADD "%key%" /v http /t REG_DWORD /d 0x2 >NUL
reg ADD "%key%" /v :Range /t REG_SZ /d %ipAddr% >NUL

Open in new window

0
 
Ryan BennettAuthor Commented:
I apologize for leaving this hanging. I had a few family emergency and totally forgot about it until I got back to work and started back into the projects I have moving forward and realized that I had spaced this off.
 I am still very interested in a solution to this question if that is still a possibility. If I can I'd like to increase the points if that is possible as well.


 Thanks so much for your post, I just tried it but all I get is a command prompt flash very quickly. I am running it from the desktop on a Virtual XP machine and have the iplist.txt file there as well. I will put a few pauses in there and post what I find out in a few minutes.
0
 
Ryan BennettAuthor Commented:
What I see so far is it is exiting the bat file at this line:
if not exist "%fileName%" echo %fileName% does not exist&goto :EOF

I placed an echo and a pause just before this line and the filename variable has the correct name so it is seeing my iplist.txt file. not sure what to try next.

 Thanks again.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AmazingTechCommented:
Is iplist.txt in the same folder as your batch file?
set fileName=ipList.txt

if not "%~1"=="" set fileName=%~1

type "%fileName%"
pause
if not exist "%fileName%" echo %fileName% does not exist&goto :EOF
pause

Open in new window

0
 
Ryan BennettAuthor Commented:
Thanks for stickin' with this....

Ok, I that was my fault, spelling issue. Got that corrected and the batch file ran, it created a trusted site for each of the entries in the iplist.txt file. The sites that are IP addresses are entered correctly, however the sites that are entered as URLs or domains are not. These are the sites that I had in the iplist.txt file:

168.179.147.215
168.179.144.17
WSNTCMSPH
*.utah.gov
*.dws.utah.gov
dwscmimaging.dws.utah.gov

And this is how they show up in the trusted sites list under internet options and in the registry:

http://168.179.147.215
http://168.179.144.17
WSNTCMSPH.
*utahgov.
*dwsutahgov.
dwscmimagingdwsutahgov.

Any ideas?

Thanks again.
RBennett
0
 
AmazingTechCommented:
Hmm... I don't know why the space was missing in:

CALL :SPLIT %ipaddr:.= %

And I was assuming URL/Domains would have atleast 1 dot. But I guess why not have shortnames for intranet urls.
@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set fileName=ipList.txt

if not "%~1"=="" set fileName=%~1

if not exist "%fileName%" echo %fileName% does not exist&goto :EOF

for /f "tokens=*" %%a in ('type "%fileName%"') do call :PROCESS "%%a" & PAUSE

goto :EOF

:PROCESS

set ipAddr=%~1
set basekey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap

echo Processing %ipAddr%

echo %ipAddr% | findstr "[a-z]"
if errorlevel 1 GOTO IPRANGE

echo %ipAddr% is a domain or url
Set Left=
Set Right=
Set Type=
CALL :SPLIT %ipaddr:.= %
GOTO :EOF


:SPLIT
if "%3" == "" (
    if "%2" == "" (
        Set Right=%1
    ) else (
        Set Right=%1.%2
    )
    if defined Left Set Left=\%Left:~1%
) Else (
    Set Left=!Left!.%1
    ECHO !Left! | findstr /i "HTTPS://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTPS & Set Left=!Left:HTTPS://=!
    ECHO !Left! | findstr /i "HTTP://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTP & Set Left=!Left:HTTP://=!
    shift
    if "%1" NEQ "" GOTO SPLIT
)

    
IF NOT DEFINED Type (
    ECHO Domain
    Set Type=*
) ELSE (
    ECHO URL
)

REG ADD "%basekey%\Domains\%Right%%Left%" /v !Type! /t REG_DWORD /f /d 0x2
GOTO :EOF

:IPRANGE

echo %ipaddr% is an IP Range
for /f "tokens=*" %%a in ('reg query "%basekey%\Ranges" 2^>^&1 ^| findstr /i "%basekey%\Ranges\Range" 2^>^&1') do (
  for /f %%b in ('reg query "%%a" 2^>^&1 ^| findstr "%ipAddr%"') do reg delete "%%a" /f >NUL
)

set /a cnt=0

:NEXTRANGE

set /a cnt+=1

set key=%basekey%\Ranges\Range%cnt%

for /f %%a in ('reg query "%key%" 2^>^&1 ^| findstr /i /c:ERROR:') do goto GOTRANGE

goto NEXTRANGE

:GOTRANGE

reg ADD "%key%" >NUL

echo Adding Range%cnt%

reg ADD "%key%" /v http /t REG_DWORD /d 0x2 >NUL
reg ADD "%key%" /v :Range /t REG_SZ /d %ipAddr% >NUL

Open in new window

0
 
Ryan BennettAuthor Commented:
Ok, I tried this last version and it appears to be working. The only difference I see between adding the  entries and using this script is that when you run the script and there is a *. before the domain name (*.utah.gov) it creates a separate key for the * . Adding them manually does not create this key.
IE... using these as an example *.utah.gov and *.dws.utah.gov
Using script:
...\ZoneMap\Domains\utah.gov
...\ZoneMap\Domains\utah.gov\*
...\ZoneMap\Domains\utah.gov*.dws

Manually entered:
...\ZoneMap\Domains\utah.gov
...\ZoneMap\Domains\utah.gov\*.dws

Not sure if this even matters or if it will cause any unforeseen problems down the road, but as is stands it appears to be working.

 Any thoughts or concerns with this as it stands right now?

Thanks.
0
 
Ryan BennettAuthor Commented:
Sorry, a few type-os in the last post... I meant....

Ok, I tried this last version and it appears to be working. The only difference I see between adding the  entries manually, and using this script is that when you run the script and there is a *. before the domain name (*.utah.gov) it creates a separate key for the * . Adding them manually does not create this key.

IE... using these as an example *.utah.gov and *.dws.utah.gov
Using script:
...\ZoneMap\Domains\utah.gov
...\ZoneMap\Domains\utah.gov\*
...\ZoneMap\Domains\utah.gov\*.dws

Manually entered:
...\ZoneMap\Domains\utah.gov
...\ZoneMap\Domains\utah.gov\*.dws

Not sure if this even matters or if it will cause any unforeseen problems down the road, but as is stands it appears to be working. What do you think?

 Any thoughts or concerns with accepting this as it stands right now?

Thanks again for the hard work.
0
 
AmazingTechCommented:
Hmm... We should fix it just in case.
@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set fileName=ipList.txt

if not "%~1"=="" set fileName=%~1

if not exist "%fileName%" echo %fileName% does not exist&goto :EOF

for /f "tokens=*" %%a in ('type "%fileName%"') do call :PROCESS "%%a" & PAUSE

goto :EOF

:PROCESS

set ipAddr=%~1
set basekey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap

echo Processing %ipAddr%

echo %ipAddr% | findstr "[a-z]"
if errorlevel 1 GOTO IPRANGE

echo %ipAddr% is a domain or url
Set Left=
Set Right=
Set Type=
CALL :SPLIT %ipaddr:.= %
GOTO :EOF


:SPLIT
if "%3" == "" (
    if "%2" == "" (
        Set Right=%1
    ) else (
        Set Right=%1.%2
    )
    if defined Left Set Left=\%Left:~1%
) Else (
    Set Left=!Left!.%1
    ECHO !Left! | findstr /i "HTTPS://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTPS & Set Left=!Left:HTTPS://=!
    ECHO !Left! | findstr /i "HTTP://">NUL
    if NOT ERRORLEVEL 1 Set Type=HTTP & Set Left=!Left:HTTP://=!
    shift
    if "%1" NEQ "" GOTO SPLIT
)

IF "%LEFT%" == "\*" Set Left=
    
IF NOT DEFINED Type (
    ECHO Domain
    Set Type=*
) ELSE (
    ECHO URL
)

REG ADD "%basekey%\Domains\%Right%%Left%" /v !Type! /t REG_DWORD /f /d 0x2
GOTO :EOF

:IPRANGE

echo %ipaddr% is an IP Range
for /f "tokens=*" %%a in ('reg query "%basekey%\Ranges" 2^>^&1 ^| findstr /i "%basekey%\Ranges\Range" 2^>^&1') do (
  for /f %%b in ('reg query "%%a" 2^>^&1 ^| findstr "%ipAddr%"') do reg delete "%%a" /f >NUL
)

set /a cnt=0

:NEXTRANGE

set /a cnt+=1

set key=%basekey%\Ranges\Range%cnt%

for /f %%a in ('reg query "%key%" 2^>^&1 ^| findstr /i /c:ERROR:') do goto GOTRANGE

goto NEXTRANGE

:GOTRANGE

reg ADD "%key%" >NUL

echo Adding Range%cnt%

reg ADD "%key%" /v http /t REG_DWORD /d 0x2 >NUL
reg ADD "%key%" /v :Range /t REG_SZ /d %ipAddr% >NUL

Open in new window

0
 
Ryan BennettAuthor Commented:
You really are Amazing. That fixed it and everything looks like its working great. Exactly what I was looking for.


 Thanks very much for your help.

RBennett
0
 
Ryan BennettAuthor Commented:
Exactly what I needed, wish I could figure out how to increase the points to so I could give you more.

 Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now