"') 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 添加多条路由">
当前位置:   article > 正文

批处理添加路由表_bat 添加多条路由

bat 添加多条路由
  1. @echo off
  2. for /F "tokens=3" %%* in ('route print ^| findstr "\<0.0.0.0\>"') do set "gw=%%*"
  3. ipconfig /flushdns
  4. route add 1.0.1.0 mask 255.255.255.0 %gw% metric 5
  5. route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5
  6. 。。。

取第一条  网关地址

  1. @echo off for /F "tokens=3" %%* in ('route print ^| findstr "\<0.0.0.0\>"') do (set "gw=%%*"&goto en):en
  2. ipconfig /flushdns
  3. route add 1.0.1.0 mask 255.255.255.0 %gw% metric 5
  4. route add 1.0.2.0 mask 255.255.254.0 %gw% metric 5
  5. 。。。。。。。。


for /F "tokens=" %%* in ('route print ^ findstr "\<...\>"') do (if not "%%*"=="9.bai8.." set "gw=%%*")

程序中代码执行批处理(c#)

  1. /// <summary>
  2. /// 路由表增删
  3. /// </summary>
  4. /// <param name="type"></param>
  5. public static void RouteChange(string type)
  6. {
  7. Process proc = null;
  8. if (Global.configRouteProcID == -1)
  9. {
  10. proc = new Process();
  11. }
  12. else
  13. {
  14. try
  15. {
  16. Process oldProc = Process.GetProcessById(Global.configRouteProcID);
  17. Console.WriteLine("processID:" + Global.configRouteProcID);
  18. oldProc.Kill();
  19. oldProc.Close();
  20. proc = new Process();
  21. }
  22. catch (Exception ex)
  23. {
  24. proc = new Process();
  25. }
  26. }
  27. try
  28. {
  29. string rootpath = AppDomain.CurrentDomain.BaseDirectory;
  30. //string rootpath = path.Substring(0, path.LastIndexOf("bin"));
  31. string routeDir = rootpath + @"Resources\route";//相对路径 @"E:\Raisecom\L2tp\RSpeedoPAC\Rspeedo\Resources\Router";//
  32. proc.StartInfo.Verb = "runas";//管理员身份
  33. proc.StartInfo.WorkingDirectory = routeDir;
  34. if (type == "add")
  35. {
  36. proc.StartInfo.FileName = "vpnup.bat"; ;
  37. }
  38. else
  39. {
  40. proc.StartInfo.FileName = "vpndown.bat";
  41. }
  42. //proc.StartInfo.Arguments = string.Format("10");//this is argument
  43. proc.StartInfo.CreateNoWindow = true;
  44. // proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  45. proc.Start();
  46. Global.configRouteProcID = proc.Id;
  47. proc.WaitForExit();
  48. proc.Close();
  49. }
  50. catch (Exception ex)
  51. {
  52. Console.WriteLine(ex.ToString());
  53. }
  54. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/177165
推荐阅读
相关标签
  

闽ICP备14008679号