In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to use raspberry pie to automatically notify python after public network IP changes? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Obtain the public network IP
Class Getmyip: def getip (self): try: myip = self.visit ("http://www.ip138.com/ip2city.asp") except Exception E1: logging.warning (str (E1)) try: myip = self.visit ("http://www.whereismyip.com") except Exception E2: logging.warning (str (e2)) myip = "So sorryroommates!" Return myip def visit (self,url): opener = urllib2.urlopen (url) # if url = = opener.geturl (): mystr = opener.read () return re.search ('\ d +\.\ d +\.\ d +\.
two。 Send an email
Def send_mail (to_list,sub,content): mail_host= "smtp.163.com" # set server mail_user= "aaa" # username mail_pass= "aaa" # password mail_postfix= "163.com" # suffix me= "hello" + "" msg = MIMEText (content,_subtype='plain' _ charset='utf8') msg ['Subject'] = sub msg [' From'] = me msg ['To'] = " ".join (to_list) try: server = smtplib.SMTP () server.connect (mail_host) server.login (mail_user,mail_pass) server.sendmail (me, to_list, msg.as_string ()) server.close () return True except Exception E: print str (e) return False
3. Check every half hour
If _ _ name__ ='_ _ main__': strLastIP =''logging.info (' Starting message') while True: logging.info ('time.sleep begin') time.sleep (1600) logging.info (' time.sleep end') getmyip = Getmyip () Logging.info ('Getmyip') localip = getmyip.getip () logging.info (' getmyip.getip ='+ localip) if localip = ='So sorryloaded cards' Or localip ='': continue if localip = = strLastIP: logging.info ("The same ip:" + localip) else: logging.info ("localip ok:" + Localip) if send_mail (mailto_list IP + localip, localip): strLastIP = localip logging.info ("send ok") else: logging.warning ("send err")
4. Boot up
Edit / etc/init.d/rc.local
Python / usr/local/work/sendmyip.py &
After reading the above, do you know how to automatically notify python after making public network IP changes through raspberry pie? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.