unity3d 手動/動態修改電腦ip地址
阿新 • • 發佈:2020-12-18
新增.bat檔案(手動/自動修改ip)
1.手動修改ip相關地址
netsh interface ip set address name="本地連線" source=static addr=192.168.199.146 mask=255.255.255.0 gateway=192.168.199.1
netsh interface ip set dns name="本地連線" source=static addr=123.1.11.1 validate=no
netsh interface ip add dns "本地連線" 211.162.96.41
2.動態獲取ip地址
netsh interface ip set address name="本地連線" source=dhcp
netsh interface ip set dns name="本地連線" source=dhcp
Uinty呼叫bat檔案
public static Process CreateShellExProcess(string cmd, string args, string workingDir = "") { var pStartInfo = new ProcessStartInfo(cmd); pStartInfo.Arguments = args; pStartInfo.CreateNoWindow = false; pStartInfo.UseShellExecute = true; pStartInfo.WindowStyle = ProcessWindowStyle.Hidden; pStartInfo.RedirectStandardError = false; pStartInfo.RedirectStandardInput = false; pStartInfo.RedirectStandardOutput = false; if (!string.IsNullOrEmpty(workingDir)) pStartInfo.WorkingDirectory = workingDir; return Process.Start(pStartInfo); } public void RunBat(string batfile, string args, string workingDir = "") { var p = CreateShellExProcess(batfile, args, workingDir); p.Close(); }
直接呼叫RunBat方法即可。