Best Tips - TM1dk

Go to content

Main menu:

Best Tips

Visit the forum for TM1 tips

Send public ip by mail

Python 3.6.5 program tips

If you have a server at home that you want to access, and you have a broadband connection to the internet with a random ip address from your ISP, then you need to know todays ip. From internet there are diffrent ways to solve this.
Buy a program from

Write your own program in python -- here an example
Install python 365 from
Install some development plattform like
To get the public ip create this lines in your python script

import requests
page = requests.get('')
ip = page.text

# test the value of variable ip by show it on terminal
print (ip)

Test and ensure above file work.

Then to send a mail with your ISP just a code like below (this example is for TELENOR):

# use smtplib functions
import smtplib
server = smtplib.SMTP_SSL('', 465)
# some ISP does not use tls instead you should use SMTP_SSL as python command
# server.starttls()
server.login("your email address", "your password")
# set the ip number as the message text
msg = "This is your public ip" + ip + " have a good day"
server.sendmail("your email adress", "the email address to send to", msg )

You need to change values above to match your login to your ISP mail server

Save both above codes in a python file called in a folder like c:\code
Download and install the program that create a exe of a python script
pip install pyinstaller

Then go to a command prompt on your server, and move to the folder where you have python installed.
cd C:\Program Files (x86)\Python36-32
Enter the below command to compile the File

pyinstaller.exe --onefile "c:\code\"

After the file is created, it can be found in folder C:\Program Files (x86)\Python36-32\dist
Copy the mypublicip.exe file to another computer and test that it works.

Now you can use the windows schedule to make it run every day if you want.

More information on how to do it at

import smtplib

server = smtplib.SMTP('', 587)


More info on how to get IP
This website http;// outputs your ip so you only need these 3 lines to get your ip.

import requests
page = requests.get('')
ip = page.text

what its doing is:

opens my webpage and calls it "page"
sets "ip" to the contents of the "page"

Search google for more python examples.
Back to content | Back to main menu