Jump to content
youtuber

About performance while loop?

Recommended Posts

youtuber

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

defaultgateway.png

 

Share this post


Link to post
Share on other sites
jguinch

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)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
youtuber

@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?

Share this post


Link to post
Share on other sites
youtuber

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

 

Share this post


Link to post
Share on other sites
Jos

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 by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
bernd670

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 by bernd670
  • Thanks 1

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Share this post


Link to post
Share on other sites
jguinch
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

  • Thanks 1

Share this post


Link to post
Share on other sites
jguinch

@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

 

  • Thanks 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.