Sign in to follow this  
Followers 0
RìggníX

Default Gateway UDF

5 posts in this topic

#1 ·  Posted (edited)

hi!

a func that returns the subnet mask. should work with windows in every language.....

sorry, made a mistake in the title of the thread :whistle:

SubnetMask, NOT default gateway

GetSubnetMask.au3

Edited by RìggníX

greetz, RìggníXBiTrAtE.tk

Share this post


Link to post
Share on other sites



erm, can an admin please change the title of this thread to "Subnet Mask UDF" and than delete this answer??

thx!


greetz, RìggníXBiTrAtE.tk

Share this post


Link to post
Share on other sites

I ran across this thread looking for a quick way to get the default gateway. I couldn't find it so I wrote it:

This code will actually get the default gateway:

MsgBox(0,"default gateway", _get_default_gateway())

Func _get_default_gateway()
    $output = _get_cmd_output("netstat -rn")
    $arr = StringSplit($output, "Default Gateway:", 1)
    $arr2 = StringSplit($arr[2], "=",1)
    Return StringReplace(StringStripWS($arr2[1],1), @LF, '')
EndFunc

Func _get_cmd_output($cmd)
    
    $cmd_timeout = 2000
    
    $pid = Run($cmd,@WorkingDir,@SW_HIDE,2)
    $timer = TimerInit()
    while (ProcessExists($pid))
        sleep(50)
        If TimerDiff($timer) > $cmd_timeout Then ProcessClose($pid)
    WEnd
    $output = StdoutRead($pid)
    
    Return StringStripCR($output)
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi!

Don't run for me.

But it's normal, because :

- I have TWO gateways (it's some ROUTE statements who choose the gateway).

- My Windows is Vista ; and Netsh changed few presentations of infos.

- My Windows is in french, and some words are translated.

Perso, for found the first (metric=1) gateway, I use :

ipconfig /ALL | find "Passerelle"

("Passerelle" is the french translation for the english word "Gateway")

@+

Edited by Michel Claveau

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0