发送当前IP到我的手机
因为家里使用ADSL上网,IP是不断变化的,就写了下面的脚本把新的IP发送到手机
上面的脚本用到了可可熊写的PyFetion,感谢可可熊的努力工作
http://cocobear.info/blog/
http://code.google.com/p/pytool/source/browse/#svn/trunk/PyFetion
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 import urllib
4 import re
5 import os
6 import ConfigParser
7 from PyFetion import PyFetion
8 p = re.compile(r"\d+.\d+.\d+.\d+")
9 ip = p.search(urllib.urlopen('http://www.7y8.com/V/ip.asp').read()).group()
10 print ip
11 ipFile = os.path.expanduser("~/.ipinfo")
12 oldIP = ""
13 try:
14 file = open(ipFile,"r")
15 oldIP = file.read()
16 except IOError:
17 pass
18
19 if ip != oldIP:
20 open(ipFile,"w").write(ip)
21 config = ConfigParser.ConfigParser()
22 config.read("/etc/myconfig.ini")
23 user = config.get("fetion","user")
24 pwd = config.get("fetion","pwd")
25 phone = PyFetion(user,pwd,"TCP",False)
26 phone.login()
27 if phone.login_ok:
28 phone.send_sms(ip)
2 # -*- coding: utf-8 -*-
3 import urllib
4 import re
5 import os
6 import ConfigParser
7 from PyFetion import PyFetion
8 p = re.compile(r"\d+.\d+.\d+.\d+")
9 ip = p.search(urllib.urlopen('http://www.7y8.com/V/ip.asp').read()).group()
10 print ip
11 ipFile = os.path.expanduser("~/.ipinfo")
12 oldIP = ""
13 try:
14 file = open(ipFile,"r")
15 oldIP = file.read()
16 except IOError:
17 pass
18
19 if ip != oldIP:
20 open(ipFile,"w").write(ip)
21 config = ConfigParser.ConfigParser()
22 config.read("/etc/myconfig.ini")
23 user = config.get("fetion","user")
24 pwd = config.get("fetion","pwd")
25 phone = PyFetion(user,pwd,"TCP",False)
26 phone.login()
27 if phone.login_ok:
28 phone.send_sms(ip)
上面的脚本用到了可可熊写的PyFetion,感谢可可熊的努力工作
http://cocobear.info/blog/
http://code.google.com/p/pytool/source/browse/#svn/trunk/PyFetion