Easiest way is to use my second post method where it strictly uses Apache (not Flask).
The advantage to just using apache to execute your script makes it way less complicated.
Would be pretty simple to it setup on a RP3.
apt-get update
apt-get install apache2
a2enmod cgi
Add the following to /etc/apache2/apache2.conf
<Directory /var/www/html>
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
Restart apache:
service apache2 restart
Install pip to handle python package installs:
apt-get install python3-pip
Satisfy library dependencies your about to use in the new ip.py script:
pip3 install requests
Create /var/www/html/ip.py:
#!/usr/bin/python3
from requests import get
print("Content-Type: text/html;charset=utf-8")
print()
ip = get('https://api.ipify.org').text
print(ip)
Make the script executable:
chmod 755 /var/www/html/ip.py
Point your web browser to http://<your_rp3_ip>/ip.py
It should return a single item on the page… your external IP address.
Let me know if it works for ya!
Edit: *Added part about making the script executable (chmod 755)