def GetNetworkGateway(network):
  """Get the gateway for a network.

  Uses "netstat -nr" on Darwin and "ip route" on Linux to read the routing
  table.

  It searches for a route with destination exactly matching the network
  parameter!

  Args:
    network: str, likely in CIDR format or default gateway,
        e.g. "1.2.3/24" or "0.0.0.0"
  Returns:
    a string like "1.2.3.4" or "link#1" or "01:02:03:04:05:06" or
    "dev wlan0", depending on the type of route and platform.
  """
  route = ROUTE.get(_GetPlatform(), None)
  logging.debug('Route: %s', str(route))
  if not route:
    return

  try:
    return_code, stdout, stderr = flight_common.Exec(route)
  except __HOLE__:
    return_code = None

  if return_code != 0 or stderr or not stdout:
    return

  gateway_pattern = (
      r'^%s\s+(via[\s\t])?'
      r'([\d\.]+|[0-9a-f:]+|link#\d+|dev [a-z\d]+)[\s\t]+' % network)
  gateway = re.search(gateway_pattern, str(stdout), re.MULTILINE)

  if gateway:
    return gateway.group(2)

  return
dataset/ETHPy150Open google/simian/src/simian/mac/client/network_detect.py/GetNetworkGateway