youtuber Posted April 4, 2018 Share Posted April 4, 2018 (edited) Friends,my system Windows 7 Ultimate x64I want to change the default gateway The following code does not work on every computer RegWrite('HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\{1EB6DC88-5D30-4291-B637-F28C06CADCA6}', 'DefaultGateway', 'REG_MULTI_SZ', '192.168.1.2') Spoiler Edited July 9, 2018 by youtuber Link to comment Share on other sites More sharing options...
jguinch Posted April 4, 2018 Share Posted April 4, 2018 You can try with this : #RequireAdmin #Include "network.au3" _SetGateways("Broadcom NetLink (TM) Gigabit Ethernet", "192.168.1.1") ; Replace "Broadcom...." by the name of the network adapter name (or connection name) youtuber 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
bernd670 Posted April 4, 2018 Share Posted April 4, 2018 Hello, try this Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.2", @SystemDir, @SW_HIDE) -p is called permanently youtuber 1 greetingsbernd I hacked 127.0.0.1 -> Link to comment Share on other sites More sharing options...
youtuber Posted April 4, 2018 Author Share Posted April 4, 2018 @jguinch I have 35 computers. Each computer has a different network adapter name and they only connect to the ethernet cable. Do I need to add network adapter name for each one separately? Link to comment Share on other sites More sharing options...
youtuber Posted April 5, 2018 Author Share Posted April 5, 2018 Is my line of code healthy or is there another alternative? The purpose of these codes is to change the default gateway if someone on the same network is using the internet, if someone is playing a game and it is detected that they are using the internet. Do you think this would be a problem? While 1 If ProcessExists('chrome.exe') Or ProcessExists('iexplore.exe') Or ProcessExists('firefox.exe') Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1", @SystemDir, @SW_HIDE) Else Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.2", @SystemDir, @SW_HIDE) EndIf Sleep(20) WEnd Link to comment Share on other sites More sharing options...
Developers Jos Posted April 5, 2018 Developers Share Posted April 5, 2018 (edited) You seriously want to shell 5 instances of route in a seconds endlessly and ask us whther this is "healthy"? You also mention the forbidden word while you should know better. Edit: Merged related threads to keep context. Jos Edited April 5, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bernd670 Posted April 5, 2018 Share Posted April 5, 2018 (edited) Hallo, this is a better way #include <AutoItConstants.au3> $DG = GetDefaultGateway() While 1 If ProcessExists('chrome.exe') Or ProcessExists('iexplore.exe') Or ProcessExists('firefox.exe') Then If ($DG <> "192.162.1.1") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1", @SystemDir, @SW_HIDE) $DG = "192.168.1.1" EndIf Else If ($DG <> "192.168.1.2") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.2", @SystemDir, @SW_HIDE) $DG = "192.168.1.2" EndIf EndIf Sleep(1000) WEnd Func GetDefaultGateway() Local $PID = Run("route print", @ScriptDir, @SW_HIDE, $STDOUT_CHILD) Local $out = "" While 1 $out &= StdoutRead($PID) If @error Then ExitLoop WEnd Return StringRegExp($out, "\s*0.0.0.0\s+0.0.0.0\s+(\d+\.\d+\.\d+\.\d+).*", 1)[0] EndFunc ;==>GetDefaultGateway Edited April 5, 2018 by bernd670 youtuber 1 greetingsbernd I hacked 127.0.0.1 -> Link to comment Share on other sites More sharing options...
jguinch Posted April 5, 2018 Share Posted April 5, 2018 20 hours ago, youtuber said: @jguinch I have 35 computers. Each computer has a different network adapter name ... You can get the network name using _GetNetworkAdapterList , get informations with _GetNetworkAdapterInfos, check if the adapter is wireless of not using _IsWirelessAdapter youtuber 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
youtuber Posted April 5, 2018 Author Share Posted April 5, 2018 I don't know exactly how to use it. #RequireAdmin #Include "network.au3" #Include <array.au3> $infos = _GetNetworkAdapterList() _ArrayDisplay($infos) _SetGateways($infos, "192.168.1.1") Spoiler Link to comment Share on other sites More sharing options...
jguinch Posted April 6, 2018 Share Posted April 6, 2018 @youtuber : here is an example or how you can do it : #RequireAdmin #Include "Network.au3" Local $aNetAdapter = _GetNetworkAdapterList() For $i = 0 To UBound($aNetAdapter) - 1 If _IsWirelessAdapter($aNetAdapter[$i][0]) Then ConsoleWrite($aNetAdapter[$i][0] & ' is a wireless adapter') Else ConsoleWrite('"' & $aNetAdapter[$i][0] & '" is not a wireless adapter') _SetGateways($aNetAdapter[$i][0], "192.168.99.1") EndIf Next youtuber 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
youtuber Posted July 8, 2018 Author Share Posted July 8, 2018 On 05.04.2018 at 8:06 PM, bernd670 said: Hallo, this is a better way #include <AutoItConstants.au3> $DG = GetDefaultGateway() While 1 If ProcessExists('chrome.exe') Or ProcessExists('iexplore.exe') Or ProcessExists('firefox.exe') Then If ($DG <> "192.162.1.1") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1", @SystemDir, @SW_HIDE) $DG = "192.168.1.1" EndIf Else If ($DG <> "192.168.1.2") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.2", @SystemDir, @SW_HIDE) $DG = "192.168.1.2" EndIf EndIf Sleep(1000) WEnd Func GetDefaultGateway() Local $PID = Run("route print", @ScriptDir, @SW_HIDE, $STDOUT_CHILD) Local $out = "" While 1 $out &= StdoutRead($PID) If @error Then ExitLoop WEnd Return StringRegExp($out, "\s*0.0.0.0\s+0.0.0.0\s+(\d+\.\d+\.\d+\.\d+).*", 1)[0] EndFunc ;==>GetDefaultGateway This works better for me, but I also want to change the DNS address I tried this for it but it does not work Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1 8.8.8.8 8.8.4.4", @SystemDir, @SW_HIDE) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 9, 2018 Developers Share Posted July 9, 2018 (edited) 9 hours ago, youtuber said: This works better for me, but I also want to change the DNS address I tried this for it but it does not work Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1 8.8.8.8 8.8.4.4", @SystemDir, @SW_HIDE) Could you please explain what you mean as you talk about DNS and the shown command is supposed to change a Route in the routing table? So what do you want to accomplish with this commandline? Jos Edited July 9, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted July 9, 2018 Author Share Posted July 9, 2018 I want to change my default gateway and Preferred DNS server Spoiler example is like this Run(@ComSpec & " /c " & "netsh interface ip set dns ""Local area network"" static 8.8.8.8", "", @SW_HIDE) can it be done with this command? Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1 8.8.8.8", @SystemDir, @SW_HIDE) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 9, 2018 Developers Share Posted July 9, 2018 8 minutes ago, youtuber said: can it be done with this command? No, but you could not find the answer to this yourself anywhere? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted July 9, 2018 Author Share Posted July 9, 2018 there are some answers but it is very complicated so I guess it works simpler and better for me Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1 8.8.8.8", @SystemDir, @SW_HIDE) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 9, 2018 Developers Share Posted July 9, 2018 It would be smart to try and understand the difference between IP routing and the purpose of DNS, but fully appreciate the fact it isn't easy when starting to look at all of this. You will find that it really isn't that difficult, but it means investing some time to learn though. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
youtuber Posted July 9, 2018 Author Share Posted July 9, 2018 yes I try for a long time but unfortunately I have not been successful I need an example I am glad you will give me an example of how to do it. Example that worked very well for me but here In addition it would be better to change the preferred DNS server and it will be exactly what I want On 05.04.2018 at 8:06 PM, bernd670 said: Hallo, this is a better way #include <AutoItConstants.au3> $DG = GetDefaultGateway() While 1 If ProcessExists('chrome.exe') Or ProcessExists('iexplore.exe') Or ProcessExists('firefox.exe') Then If ($DG <> "192.162.1.1") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.1", @SystemDir, @SW_HIDE) $DG = "192.168.1.1" EndIf Else If ($DG <> "192.168.1.2") Then Run("route -p change 0.0.0.0 mask 0.0.0.0 192.168.1.2", @SystemDir, @SW_HIDE) $DG = "192.168.1.2" EndIf EndIf Sleep(1000) WEnd Func GetDefaultGateway() Local $PID = Run("route print", @ScriptDir, @SW_HIDE, $STDOUT_CHILD) Local $out = "" While 1 $out &= StdoutRead($PID) If @error Then ExitLoop WEnd Return StringRegExp($out, "\s*0.0.0.0\s+0.0.0.0\s+(\d+\.\d+\.\d+\.\d+).*", 1)[0] EndFunc ;==>GetDefaultGateway Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now