How to get gateway address?

The script i have calls and checks gateway address.

What i have been using

property vpnip : "    gateway: 1.1.1.1" #changed for protection
property localgatewayip : "    gateway: 2.2.2.2" #changed for protection
set theGateway to do shell script "route get default | grep gateway"
				if theGateway = localgatewayip or theGateway = vpnip then

is there a way to get just the ip and not the " gateway: 1.1.1.1"

Hi,

use egrep with regular expression


do shell script "route get default | egrep -o '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}'"

if i do

set theVPN to do shell script "netstat -rn | grep UGScI | tr -s \" \" | cut -d\" \" -f2"

i get my vpn gateway
but
if i do

set theVPN to do shell script "netstat -rn | grep UGSc | tr -s \" \" | cut -d\" \" -f2"

i get both gateway and vpn gateway. is there a way to check both gateways and if one of them is right the proceed???


property vpnip : "1.1.1.201" #changed for protection
property localgatewayip : "    gateway: 1.1.1.1" #changed for protection

repeat
	set testIP to chkUP("http://www.apple.com") or chkUP("http://www.google.com")
	if testIP then
		repeat
			try
				set theGateway to do shell script "route get default | grep gateway"
				set theVPN to do shell script "netstat -rn | grep UGScI | tr -s \" \" | cut -d\" \" -f2"
				if theGateway = localgatewayip or theVPN = vpnip then


Stefan’s script will return the default gateway. There can only be one default gateway in tcp/ip and all other gateways will overrule the default. So when a tcp packet doesn’t match any of those other gateways it will be send to the default gateway. Unless you mean something else with “right”?