A7J
A7J

Reputation: 3

How do I check public IP using Python or DDNS with Cloudflare

It's any way to check my public IP addres using Python? I have had an account on Cloudflare and VPS in a home (but dynamic IP). I need to update VPN IP'S before had an account on OVH and DDNS works after migration dose not work.

Upvotes: 0

Views: 882

Answers (3)

Marcelo Waisman
Marcelo Waisman

Reputation: 596

Recently I've created a simple docker image that allows you to keep you local ip in sync with Cloudflare AKA Cloudflare Dynamic DNS (DDNS) check it out here: https://github.com/marcelowa/cloudflare-dynamic-dns

Upvotes: 0

Josh Spicer
Josh Spicer

Reputation: 1

There's a bunch of websites online that offer simple APIs to check the IP address you're connecting from.

As an example:

➜ ~ curl 'https://api.ipify.org?format=json'
{"ip":"1.2.3.4"}

You can use a python library (like Requests) to call the API in python code.

# download requests with `pip install requests`

import requests
res = requests.get("https://api.ipify.org?format=json")

your_ip = res.json() # {"ip" : "1.2.3.4"}

Upvotes: 0

bathman
bathman

Reputation: 305

requests:

import requests
response = requests.get('http://ifconfig.me')
print(response.text)

python 2:

import urllib2
response = urllib2.urlopen('http://ifconfig.me')
print response.read()

python 3:

from urllib import request
response = request.urlopen('http://ifconfig.me')
print(response.read())

Upvotes: 1

Related Questions