当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 6 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 10:04 

注册: 2009-01-01 14:06
帖子: 39
送出感谢: 0 次
接收感谢: 0 次
#!/usr/bin/env python3
# vim:fileencoding=utf-8
import os
import base64
import smtplib
import urllib.request
from subprocess import check_call, PIPE
iffile = '/tmp/ip'

def getlastip():
try:
return open(iffile).read()
except IOError:
return False
def getcurip():
return urllib.request.urlopen('http://icanhazip.com/').read().rstrip().decode()
def mailip(ip):
check_call(['/usr/local/sbin/cjb-update.sh'], stdout=PIPE)
s = smtplib.SMTP('smtp.126.com')
status = s.login('xxx', base64.decodebytes(b'yyy').decode())[0]
if status == 235:
msg = 'From: xxx\r\n'\
'To: yyy\r\n'\
'Subject: latest ip\r\n'\
'\r\n'
msg += ip
s.sendmail('xxx', 'yyy', msg)
else:
return False
s.quit()
def main():
while True:
curip = getcurip()
if not curip.strip():
# 有时会得到空内容
continue
if curip != getlastip():
open(iffile, 'w').write(curip)
mailip(curip)
break

if __name__ == '__main__':
main()


页首
 用户资料  
 
2 楼 
 文章标题 : Re: 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 10:19 

注册: 2008-05-24 8:30
帖子: 1453
送出感谢: 2
接收感谢: 30
贴代码贴在代码块中,尤其是python代码,不放代码块中,缩进都没了,代码本身就不正确了。


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 11:28 
头像

注册: 2010-06-16 1:05
帖子: 14668
地址: Tencent
系统: Mac OS X
送出感谢: 1
接收感谢: 153
无力吐槽,这样子的py能看才奇怪了


_________________
twitter求fo:http://twitter.com/maplebeats
博客求踩:http://maplebeats.com


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 12:58 
头像

注册: 2008-08-13 8:48
帖子: 26391
地址: 东海硇州,一双管钥。
系统: Fundu i64
送出感谢: 50
接收感谢: 344
[python]
#!/usr/bin/env python3
# vim:fileencoding=utf-8
import os
import base64
import smtplib
import urllib.request
from subprocess import check_call, PIPE
iffile = '/tmp/ip'
def getlastip():
try:
return open(iffile).read()
except IOError:
return False
def getcurip():
return urllib.request.urlopen('http://icanhazip.com/').read().rstrip().decode()
def mailip(ip):
check_call(['/usr/local/sbin/cjb-update.sh'], stdout=PIPE)
s = smtplib.SMTP('smtp.126.com')
status = s.login('xxx', base64.decodebytes(b'yyy').decode())[0]
if status == 235:
msg = 'From: xxx\r\n'\
'To: yyy\r\n'\
'Subject: latest ip\r\n'\
'\r\n'
msg += ip
s.sendmail('xxx', 'yyy', msg)
else:
return False
s.quit()
def main():
while True:
curip = getcurip()
if not curip.strip():
# 有时会得到空内容
continue
if curip != getlastip():
open(iffile, 'w').write(curip)
mailip(curip)
break
if __name__ == '__main__':
main()
[/python]
http://p.vim-cn.com/cGW/python
那么好看的代码居然被弄成这样,看的心情都没了。 :em04 :em04 :em04


_________________
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关


页首
 用户资料  
 
5 楼 
 文章标题 : Re: 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 14:49 
头像

注册: 2009-04-11 23:46
帖子: 4130
系统: Arch Linux
送出感谢: 11
接收感谢: 124
YeLee 写道:
[python]
#!/usr/bin/env python3
# vim:fileencoding=utf-8
import os
import base64
import smtplib
import urllib.request
from subprocess import check_call, PIPE
iffile = '/tmp/ip'
def getlastip():
try:
return open(iffile).read()
except IOError:
return False
def getcurip():
return urllib.request.urlopen('http://icanhazip.com/').read().rstrip().decode()
def mailip(ip):
check_call(['/usr/local/sbin/cjb-update.sh'], stdout=PIPE)
s = smtplib.SMTP('smtp.126.com')
status = s.login('xxx', base64.decodebytes(b'yyy').decode())[0]
if status == 235:
msg = 'From: xxx\r\n'\
'To: yyy\r\n'\
'Subject: latest ip\r\n'\
'\r\n'
msg += ip
s.sendmail('xxx', 'yyy', msg)
else:
return False
s.quit()
def main():
while True:
curip = getcurip()
if not curip.strip():
# 有时会得到空内容
continue
if curip != getlastip():
open(iffile, 'w').write(curip)
mailip(curip)
break
if __name__ == '__main__':
main()
[/python]
http://p.vim-cn.com/cGW/python
那么好看的代码居然被弄成这样,看的心情都没了。 :em04 :em04 :em04

囧,我的空行呢?复制不过来?你什么浏览器?


_________________
我的博客 https://blog.lilydjwg.me/
提问的智慧
Arch Linux 中文论坛

我的vimrc: https://git.io/vimrc


页首
 用户资料  
 
6 楼 
 文章标题 : Re: 谁能帮我解释下下面脚本的含义
帖子发表于 : 2012-05-20 16:18 
头像

注册: 2008-08-13 8:48
帖子: 26391
地址: 东海硇州,一双管钥。
系统: Fundu i64
送出感谢: 50
接收感谢: 344
lilydjwg 写道:
YeLee 写道:
[python]
#!/usr/bin/env python3
# vim:fileencoding=utf-8
import os
import base64
import smtplib
import urllib.request
from subprocess import check_call, PIPE
iffile = '/tmp/ip'
def getlastip():
try:
return open(iffile).read()
except IOError:
return False
def getcurip():
return urllib.request.urlopen('http://icanhazip.com/').read().rstrip().decode()
def mailip(ip):
check_call(['/usr/local/sbin/cjb-update.sh'], stdout=PIPE)
s = smtplib.SMTP('smtp.126.com')
status = s.login('xxx', base64.decodebytes(b'yyy').decode())[0]
if status == 235:
msg = 'From: xxx\r\n'\
'To: yyy\r\n'\
'Subject: latest ip\r\n'\
'\r\n'
msg += ip
s.sendmail('xxx', 'yyy', msg)
else:
return False
s.quit()
def main():
while True:
curip = getcurip()
if not curip.strip():
# 有时会得到空内容
continue
if curip != getlastip():
open(iffile, 'w').write(curip)
mailip(curip)
break
if __name__ == '__main__':
main()
[/python]
http://p.vim-cn.com/cGW/python
那么好看的代码居然被弄成这样,看的心情都没了。 :em04 :em04 :em04

囧,我的空行呢?复制不过来?你什么浏览器?

fx 10.0.4 :em06 :em06 :em06


_________________
◎当我站在道德的高度上俯视别人的时候,发现自己是多么渺小。
♥执着但不偏激,反对而不排斥,坚决捍卫矛盾体的存在方式。
★★★天气预报★★★
fcitx-yatable一个可以使用的码表输入法
[教程]几个实例攻克软件编译难关
Gentoo Development Guide
字体相关


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 6 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译