因为笔记本要在家里和公司之间背来背去,而家里和公司的无线网卡设置不同。
家里为了方便,无线路由器设置成自动拨号,所有机子通过dhcp接入;而公司里管理较严格,要求设置成固定ip。
每次换个地方就要重新设置无线网卡,一个弹窗一个弹窗地打开、设置,很不方便。
所以为了偷懒,做了下面这个批处理命令:
1
@echo
off
2 title set wlan interface
3
4 :begin
5 set choice=p
6
7 :main
8 :loop
9 call :show_help
10 if /i "%choice%"=="a" (
11 call :set_dhcp Homewlan
12 ) else if /i "%choice%"=="b" (
13 call :set_static Companywlan
14 ) else if /i "%choice%"=="l" (
15 netsh interface ipv4 show address wlan0
16 netsh interface ipv4 show dnsservers wlan0
17 ) else if /i "%choice%"=="q" (
18 echo bye bye
19 goto :end
20 )
21 set /p choice="enter your choice: "
22 goto :loop
23 goto :end
24
25 :set_dhcp
26 setlocal
27 netsh interface ipv4 set address wlan0 dhcp
28 netsh wlan connect name= %1 interface=wlan0
29 netsh interface ipv4 set dnsservers wlan0 dhcp
30 endlocal
31 goto :EOF
32
33 :set_static
34 setlocal
35 netsh interface ipv4 set address wlan0 static 172.18.1.77 255.255.255.0 172.18.1.1
36 netsh wlan connect name= %1 interface=wlan0
37 netsh interface ipv4 set dnsservers wlan0 static 58.20.127.170 primary
38 endlocal
39 goto :EOF
40
41 :show_help
42 setlocal
43 cls
44 echo ========================================================
45 echo ==== wlan settings ====
46 echo ========================================================
47 echo ==== [a]. at home ====
48 echo ==== [b]. at company ====
49 echo ==== [l]. list out wlan settings ====
50 echo ==== [q]. quit wlan settings ====
51 echo ========================================================
52 echo.
53 endlocal
54 goto :EOF
55
56 :end
2 title set wlan interface
3
4 :begin
5 set choice=p
6
7 :main
8 :loop
9 call :show_help
10 if /i "%choice%"=="a" (
11 call :set_dhcp Homewlan
12 ) else if /i "%choice%"=="b" (
13 call :set_static Companywlan
14 ) else if /i "%choice%"=="l" (
15 netsh interface ipv4 show address wlan0
16 netsh interface ipv4 show dnsservers wlan0
17 ) else if /i "%choice%"=="q" (
18 echo bye bye
19 goto :end
20 )
21 set /p choice="enter your choice: "
22 goto :loop
23 goto :end
24
25 :set_dhcp
26 setlocal
27 netsh interface ipv4 set address wlan0 dhcp
28 netsh wlan connect name= %1 interface=wlan0
29 netsh interface ipv4 set dnsservers wlan0 dhcp
30 endlocal
31 goto :EOF
32
33 :set_static
34 setlocal
35 netsh interface ipv4 set address wlan0 static 172.18.1.77 255.255.255.0 172.18.1.1
36 netsh wlan connect name= %1 interface=wlan0
37 netsh interface ipv4 set dnsservers wlan0 static 58.20.127.170 primary
38 endlocal
39 goto :EOF
40
41 :show_help
42 setlocal
43 cls
44 echo ========================================================
45 echo ==== wlan settings ====
46 echo ========================================================
47 echo ==== [a]. at home ====
48 echo ==== [b]. at company ====
49 echo ==== [l]. list out wlan settings ====
50 echo ==== [q]. quit wlan settings ====
51 echo ========================================================
52 echo.
53 endlocal
54 goto :EOF
55
56 :end
现在,每次换地方,只要运行一下这个批处理就好啦。 ^_^