Bin neu hier im Forum und hoffe ich bin hier richtig mit meinem Anliegen!
Hab für mein Raspberry Pi (raspbian) ein Skript geschrieben, das mir via sendEmail die externe IP-Adresse des Raspberry Pi schickt, sobald diese sich ändert.
Da ich noch nicht so viel Erfahrung mit Linux und Python habe, würde ich gerne wissen ob sich am Code etwas verbessern lässt und ob es "sauber" programmiert ist.
Bin für Vorschläge offen! Danke schonmal!
Code: Alles auswählen
#!/usr/bin/python3
import os, time
def getIP():
os.system('dig +short myip.opendns.com @resolver1.opendns.com > raspip.txt')
with open('raspip.txt', 'r') as f:
return f.readline().rstrip('\n')
def sendIP(currentIP):
os.system('sendEmail ' + #sendEmail Applikation
'-o tls=yes ' + #use TLS
'-f \'***@outlook.com\' ' + #Sender
'-t \'***@outlook.com\' ' + #Empfänger
'-s \'smtp.live.com\' ' + #SMTP Server
'-xu \'***@outlook.com\' ' + #user
'-xp \'**password**\' ' + #password
'-u \"raspberry via python\" ' + #Betreff
'-m \"' + currentIP + '\"') #Inhalt
def main():
lastIP = None
while (True):
currentIP = getIP()
if (lastIP != currentIP):
sendIP(currentIP)
lastIP = currentIP
time.sleep(60)
if __name__ == "__main__":
main()