IP Address of Google App engine application

18,529

Solution 1

GAE uses different IPs. If you'd like more info I found this link:

https://cloud.google.com/appengine/kb/#static-ip

Solution 2

(Jun 2021): The previous/existing answers no longer reflect today's current practices (and in fact, that documentation page has been removed). As a cloud service, the IP blocks are ephemeral and rotate.

Similar to the script posted by @speedplane is the one on this page so you can see what the possible address blocks are for traffic coming from App Engine (outbound IP addresses). However, if your purpose is to use App Engine with static IP addresses, you have two different options based on whether it's inbound or outbound.

The current recommendation (as of 2020) for inbound static IP users is to create a load balancer with a static IP that redirects to your App Engine (and other) apps. See these resources for more information:

  1. The load balancer and CDN announcement (Jul 2020)
  2. Cloud Load Balancing product documentation

For outbound static IP addresses, you would create a VPC network, associate a static IP with it, and route all your App Engine traffic through the VPC and out to the Internet via a Cloud NAT gateway and your specified static IP address. See these resources for more information:

  1. Outbound IP addresses page in the App Engine docs
  2. Serverless VPC access page
  3. Cloud NAT product pages

(Jan 2022 update): I refactored that script above (to get the current rotating IP blocks) to clean it up a bit and to make it Python 2-3 compatible and got the Google networking tools team to publish it in an open source repo for any community-contributed updates. I'm working to get this new version integrated into various pages in the Google Cloud documentation, so stay tuned for that.

Solution 3

Google does have documentation on how to do this, but there are quite a few commands you need to run just to get the up-to-date IP address range. Rather than do that every time, I've written a small python script that will perform those actions and pull up-to-date IP address ranges.

To run run the code below, just call print(list(get_all_ip_cidrs())):

import re
import logging
import subprocess

def get_netblock_ips_cidr(netblock_id):
    '''Run the nslookup comamnd on the given netlock, and yield all of the ip
     address cidr addresses'''
    netblock = "_cloud-netblocks%d.googleusercontent.com"%netblock_id
    logging.info("Running Netblock %s", netblock)
    CMD = 'nslookup -q=TXT %s 8.8.8.8'%netblock
    p = subprocess.Popen(CMD, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    out, err = p.communicate()
    re_ips = re.compile(r"ip4:(?P<ipcidr>[\.\d]+/\d+)")
    num = 0
    for m in re_ips.finditer(out):
        yield m.group('ipcidr')
        num += 1
    logging.info("Netblock %s: Found %d IPs", netblock, num)

def get_all_ip_cidrs(max_net_block_ranges = 10):
    '''Run it across '''
    netblock_id = 0
    for netblock_id in range(1, max_net_block_ranges):
        for cidr in get_netblock_ips_cidr(netblock_id):
            yield cidr
    logging.info("Finished after %d netblocks"%netblock_id)
Share:
18,529
Rams
Author by

Rams

{{techie_profile}}

Updated on August 05, 2022

Comments

  • Rams
    Rams almost 2 years

    I have deployed an application in Google App engine.

    I'm able to get the IP address of the machine where this app deployed but my question is does this app always runs on same IP or any chance of running on different IP.

    Because google app engine is a cloud solution , it runs multiple instances at a time in multiple places.

    Thanks

  • user1511956
    user1511956 over 2 years
    This link is outdated / broken