當前位置:首頁 » 網路連接 » 批處理bat連接網路
擴展閱讀
怎麼切換無線wifi網路 2025-07-05 00:49:08
影偵探手機軟體免費版 2025-07-05 00:48:15

批處理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了