Sign in to follow this  
Followers 0
BinaryBrother

Get Default Gateway

3 posts in this topic

#1 ·  Posted (edited)

Func _GetGatewayIP()
    Local $StreamHandle, $StreamOutput, $DG
    If @OSVersion = "WIN_7" Then
        $StreamHandle = Run(@ComSpec & ' /c ipconfig /ALL | find "Gateway"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        If @error Then
            SetError(1)
            Return
        EndIf
        While 1
            $StreamOutput &= StdoutRead($StreamHandle)
            If @Error then ExitLoop
        WEnd
        $DG = StringRegExp($StreamOutput, "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}",3)
        If IsArray($DG) Then
            Return $DG[0]
        Else
            SetError(2)
            Return
        endif
    EndIf
EndFunc

The ipconfig output changed from XP to Win7, so I'm not sure if this will work for XP. Works fine for single gateway configurations on 7 though. :mellow:

Other examples were either designed for XP or utilized a temp file, this is an improvement over most other versions I've seen floating around the forums.

Edited by BinaryBrother

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