当前位置:首页 » 网络连接 » 批处理bat连接网络
扩展阅读
人民网网络安全工作室 2025-07-05 04:39:51
手机没网络也能玩游戏 2025-07-05 04:02:35

批处理bat连接网络

发布时间: 2022-07-19 09:08:49

‘壹’ 如何用批处理文件修改网络连接

将下面脚本保存成一个批处理文件,如lan.bat,之后双击执行该文件即可。
需要作相应的修改,
下面每一行都可以独立出来,如果哪一个配置没有,就去掉哪一行,
譬如如果备用DNS没有,那么那一行就去掉,netsh interface ip set address name="本地连接" source=static addr=192.168.0.241 mask=255.255.255.0
netsh interface ip set address name="本地连接" gateway=192.168.0.254 gwmetric=0
netsh interface ip set dns name="本地连接" source=static addr=202.96.128.68 register=PRIMARY
netsh interface ip add dns name="本地连接" addr=61.144.56.100 index=2
netsh interface ip set wins name="本地连接" source=static addr=none 注意,这段脚本是并不适用于所有机器的,需要做相应的调整其中addr为IP地址(位于第一行)
mask为子网掩码(位于第一行)
gateway为默认为网关(位于第二行)

‘贰’ bat--批处理--判断网络的连接状态

本人没用宽带连接拨号上网,所以没那个环境来测试~
不过你可以用另一种方法,就是说当“宽带连接”不停的断开--连接---断开....的时候,连接DNS服务器肯定是:通---断---通 的现象,于是转换为用检测DNS的通或断来判断这种状态~
步骤:
先要知道你们当地电信或网通的DNS服务器地址(根据你的网络来选择)
然后检测DNS服务器的连通状态~
代码:
@echo off&ping -n 1 DNS服务器地址 >nul&if not errorlevel 1 (
ping -n 1 DNS服务器地址 >nul&if errorlevel 1 start a.exe) else (
start a.exe)
%0

如果机器是使用固定的IP和DNS地址,则可以自动获取它的DNS,不需要取查了,
代码是:
netsh -c interface ip mp >%temp%\interface.txt
for /f "skip=12 tokens=5 " %%i in (%temp%\interface.txt) do set dns=%%i & goto start
:start
ping -n 1 %dns% >nul&if not errorlevel 1 (
ping -n 1 %dns% >nul&if errorlevel 1 start a.exe) else (
start a.exe)
goto start
以上方法可以间接地判断断开--连接---断开这种状态~ 至于是不是你的密码错误造成的原因不好说~

‘叁’ 怎么使用批处理bat设置静态IP地址和动态IP

以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
@echo off
%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("""%~f0""","rem",,"runas",1)(window.close)&exit
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "interface="
>"%tmp%\j.j" echo;while(!WSH.StdIn.AtEndOfStream){WSH.echo(WSH.StdIn.ReadLine().replace(/\s*$/,''));}
set comm=wmic nic where "NetEnabled=TRUE" get NetConnectionID /value
setlocal enabledelayedexpansion
for /f "tokens=1* delims==" %%a in ('%comm%^|cscript -nologo -e:jscript "%tmp%\j.j"') do (
set /a n+=1
echo;!n!、%%b
set "_#!n!=%%b"
)
echo;
set "c="
set /p c=选择需要设置的网络连接/适配器,输入数字序号并按回车键:
if defined _#%c% (set "interface=!_#%c%!") else (
set /p interface=输入需要设置的网络连接/适配器的名称:
)
if not defined interface (echo;Failed to get interface name&goto end)
echo;
echo;1、固定/静态IP
echo;2、动态IP
echo;
set "c="
set /p c=选择设置IP的方式,输入数字序号并按回车键:
if "%c%" equ "1" goto sub1
if "%c%" equ "2" goto sub2
goto end
:sub1
set ip=静态IP
set mask=子网掩码
set gateway=网关
set dns1=主DNS
set dns2=次DNS
netsh interface ip set address name="%interface%" source=static address=%ip% mask=%mask% gateway=%gateway%
netsh interface ip set dns name="%interface%" source=static address=%dns1% register=PRIMARY
if defined dns2 (netsh interface ip add dns name="%interface%" address=%dns2% index=2)
goto end
:sub2
netsh interface ip set address name="%interface%" source=dhcp
netsh interface ip set dns name="%interface%" source=dhcp
:end
echo;%#% +%$%%$%/%@% %z%
pause
exit

‘肆’ 谁教我用BAT批处理快速建立宽带连接请别胡说八道!

http://www.10gb.cn/Soft/Soft_3152.htm
首先上面的117K的小程序可以完成您要的目的。但不是BAT,是EXE。

然后用VB也可以。

Set objShell = CreateObject("Wscript.Shell")
strCommandLine = "Rasphone -a"
objShell.Run(strCommandLine)
set WshShell = CreateObject("WScript.Shell")
WScript.Sleep 200
WshShell.SendKeys "r"
WScript.Sleep 30
WshShell.SendKeys "{ENTER}"
WScript.Sleep 30
WshShell.SendKeys "{ENTER}"
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\宽带连接.lnk")
oShellLink.TargetPath = "%windir%\system32\Rasphone.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "CTRL+SHIFT+K"
oShellLink.IconLocation = "%windir%\system32\Rasphone.exe, 0"
oShellLink.Description = "宽带连接"
oShellLink.WorkingDirectory = "%windir%\system32\"
oShellLink.Save

文件名 .vbs

都不是BAT。供您参考。

‘伍’ 宽带连接批处理 bat,需要满足另外两条件

@echooff
setdns=218.85.157.99
ping%dns%|findstrTTL&&gotoend
for/l%%iin(1,1,3)do(
rasdial宽带连接ZZZZZMMMMM
ping-n3127.1>nul
ping%dns%|findstrTTL&&gotoend
ping-n21127.1>nul)
goto:eof
:end
startz:aaa.exe

‘陆’ 运行bat文件修改了网络配置,结果现在连网都连不上了,怎么办

这个批处理文件,就是更改ip地址。肯定改错了TCP/IP协议。你手动改回来就行了!
打开本地连接,右击属性,修改TCP/IP的参数。如果你有路由器,ip和dns选择自动获取就行了,否则选择你正确的ip值,dns使用批处理中的114.114.114.114也行!

‘柒’ 怎样用批处理连接宽带

①新建文本文档
②输入命令:rasdial "宽带连接" 宽带帐号 密码。
③ 另存为:宽带连接.bat(扩展名)
④双击批处理即可。

如要开机就连接宽带,将宽带连接创建一个快捷方式,然后保存在开始→启动文件夹内即可。

‘捌’ 找人写一个断网再联网的BAT批处理

::断开宽带接连
rasdial /disconnect

::连接宽带,失败自动重连,成功开启网络 ,“宽带连接”为默认名称,也可能不是这名
:loop
rasdial 宽带连接 username password || goto :loop &&start www..com

‘玖’ 如何用DOS命令(BAT批处理)设置 WIFI网络共享

手动设置吧,用bat不太好好实现。手动操作一次不就ok了