"') do (set "gw=%%*"&goto en):enipconfig /flushdnsroute add 1.0.1.0 mask 255.255.255.0 %gw% metric 5route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5。._bat 添加多条路由">
赞
踩
- @echo off
- for /F "tokens=3" %%* in ('route print ^| findstr "\<0.0.0.0\>"') do set "gw=%%*"
-
- ipconfig /flushdns
-
- route add 1.0.1.0 mask 255.255.255.0 %gw% metric 5
- route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5
- 。。。
取第一条 网关地址
- @echo off for /F "tokens=3" %%* in ('route print ^| findstr "\<0.0.0.0\>"') do (set "gw=%%*"&goto en):en
-
-
- ipconfig /flushdns
-
- route add 1.0.1.0 mask 255.255.255.0 %gw% metric 5
- route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5
- 。。。。。。。。
或
for /F "tokens=" %%* in ('route print ^ findstr "\<...\>"') do (if not "%%*"=="9.bai8.." set "gw=%%*")
程序中代码执行批处理(c#)
- /// <summary>
- /// 路由表增删
- /// </summary>
- /// <param name="type"></param>
- public static void RouteChange(string type)
- {
- Process proc = null;
- if (Global.configRouteProcID == -1)
- {
- proc = new Process();
- }
- else
- {
- try
- {
- Process oldProc = Process.GetProcessById(Global.configRouteProcID);
- Console.WriteLine("processID:" + Global.configRouteProcID);
- oldProc.Kill();
- oldProc.Close();
- proc = new Process();
- }
- catch (Exception ex)
- {
- proc = new Process();
- }
-
-
- }
- try
- {
- string rootpath = AppDomain.CurrentDomain.BaseDirectory;
- //string rootpath = path.Substring(0, path.LastIndexOf("bin"));
- string routeDir = rootpath + @"Resources\route";//相对路径 @"E:\Raisecom\L2tp\RSpeedoPAC\Rspeedo\Resources\Router";//
-
- proc.StartInfo.Verb = "runas";//管理员身份
- proc.StartInfo.WorkingDirectory = routeDir;
- if (type == "add")
- {
- proc.StartInfo.FileName = "vpnup.bat"; ;
- }
- else
- {
- proc.StartInfo.FileName = "vpndown.bat";
- }
- //proc.StartInfo.Arguments = string.Format("10");//this is argument
- proc.StartInfo.CreateNoWindow = true;
- // proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
- proc.Start();
- Global.configRouteProcID = proc.Id;
- proc.WaitForExit();
- proc.Close();
-
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。