Forums

How do I get my public IP address

Hello! I was having issues with users unable to get their confirmation link email so I contacted my mail service provider(Zoho Mail) and this was their reply:

Thank you for contacting support. It would much appreciated, if you could let us know if your using the zoho smtp server to send out the password  reset link, If yes, please help us with the Public IP address from which the connection is originated to our SMTP server, complete connection log taken from the backend of the application from which you are establishing the connection to our SMTP server.  With these information, we will be able to analyze further and assist accordingly. If you are referring some other, please explain your issue in a detailed description, so that we can check and assist you further.

So, how to i get the public IP address requested

If this is coming from your website, it might vary over time as we move the site from server to server in order to balance load across the cluster. A good way to find out what the IP address currently is is to use the ipify module -- you can install it using pip.

Hi, I need to put my web app's IP address on a whitelist for an external application. I understand the IP changes over time, but is there a range or pattern that it is allocated from?

Our IP addresses are currently from the Amazon US-east-1 region. You can see the range here.

Great, thank you!

BTW if there's a side channel you can use (for example, the provider has an API that is not reliant on IP whitelisting) then you can write code that "auto-whitelists" the IP address it is using when it starts up. There some ideas on this help page, and some ideas for doing it with Mongo that you might be able to adapt are here.

Maybe it will help someone on aws:

If for whatever reason you need to whitelist your ip in ec2. You can use boto3: - Create IAM Role with the service access you need to access in my case it was ec2 - Get the programatic Access keys - create a client and provide keys with the region and service you want to access

current ip

ip = requests.get("https://api.ipify.org?format=json").json()["ip"]

client = boto3.client('ec2',
                      aws_access_key_id=idkey,
                      aws_secret_access_key=secret,
                      region_name="eu-east-1") # make sure the right region

sg_rules_list = [{'SecurityGroupRuleId': 'sgr-000000000', # specific rule id
                  'SecurityGroupRule': {
                      'IpProtocol': 'tcp',
                      'FromPort': 7,
                      'ToPort': 7,
                      'CidrIpv4': str(ip)+'/32',
                      'Description': 'your rule description'
                  }
                  }
                 ]
  response = client.modify_security_group_rules(GroupId='sg-000000000000', #specific rule id 
                                                  SecurityGroupRules=sg_rules_list)

that should whitelist your current ip for the specific security group