Map a drive based on the IP address of the PC

  • Thread starter Thread starter Patrick
  • Start date Start date
P

Patrick

We are trying to modify our logon script to be able to map
a network drive based on the IP address of the PC. Can
this be done? Is there an environment variable that stores
the IP address of the PC? Appreciate any help. Thanks.
 
Patrick said:
We are trying to modify our logon script to be able to map
a network drive based on the IP address of the PC. Can
this be done? Is there an environment variable that stores
the IP address of the PC? Appreciate any help. Thanks.

C:\cmd>for /f "tokens=2* delims=:. " %a in ('ipconfig /all ^| findstr /c:"IP Address"') do @set IP_Address=%b

C:\cmd>set IP_Address
IP_Address=129.33.165.194
 
-----Original Message-----


C:\cmd>for /f "tokens=2* delims=:. " %a in
('ipconfig /all ^| findstr /c:"IP Address"') do @set
IP_Address=%b
C:\cmd>set IP_Address
IP_Address=129.33.165.194

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
.


How do you include this in a batch file (our logon script
is in .bat format). Also, we only need the first three
octet of the ip address to compare.... (XXX.XXX.XXX.na)
Thanks again for your assistance.
 
Patrick said:
('ipconfig /all ^| findstr /c:"IP Address"') do @set
IP_Address=%b


i l




How do you include this in a batch file (our logon script
is in .bat format). Also, we only need the first three
octet of the ip address to compare.... (XXX.XXX.XXX.na)
Thanks again for your assistance.


C:\cmd>demo\FirstThreeofIP
first_three=129.33.165
No match.

C:\cmd>rlist demo\FirstThreeofIP.cmd
=====begin C:\cmd\demo\FirstThreeofIP.cmd ====================
01. @echo off
02. setlocal
03. for /f "tokens=2* delims=:. " %%a in (
04. 'ipconfig /all ^| findstr /c:"IP Address"'
05. ) do set IP_Address=%%b
06. for /f "tokens=1-3 delims=." %%a in (
07. "%IP_Address%"
08. ) do set first_three=%%a.%%b.%%c
09. set first_three
10. if "%first_three%" equ "123.45.67" (
11. echo Match.
12. ) else (
13. echo No match.
14. )
=====end C:\cmd\demo\FirstThreeofIP.cmd ====================
 
-----Original Message-----



C:\cmd>demo\FirstThreeofIP
first_three=129.33.165
No match.

C:\cmd>rlist demo\FirstThreeofIP.cmd
=====begin C:\cmd\demo\FirstThreeofIP.cmd ====================
01. @echo off
02. setlocal
03. for /f "tokens=2* delims=:. " %%a in (
04. 'ipconfig /all ^| findstr /c:"IP Address"'
05. ) do set IP_Address=%%b
06. for /f "tokens=1-3 delims=." %%a in (
07. "%IP_Address%"
08. ) do set first_three=%%a.%%b.%%c
09. set first_three
10. if "%first_three%" equ "123.45.67" (
11. echo Match.
12. ) else (
13. echo No match.
14. )
=====end C:\cmd\demo\FirstThreeofIP.cmd ====================


--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l
.

Thank you very much for this code. I am trying to
incorporate it now with our domain logon script.
We have been struggling with this for months now.
Thank again Phil!
 
Patrick said:
i l



Thank you very much for this code. I am trying to
incorporate it now with our domain logon script.
We have been struggling with this for months now.
Thank again Phil!

You're welcome. Please let us know how it turns out.
 
Back
Top