pyexpect

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# This connects to the openbsd ftp site and
# downloads the recursive directory listing.
import pexpect
child = pexpect.spawn ('ftp ftp.openbsd.org')
child.expect ('Name .*: ')
child.sendline ('anonymous')
child.expect ('Password:')
child.sendline ('noah@example.com')
child.expect ('ftp> ')
child.sendline ('cd pub')
child.expect('ftp> ')
child.sendline ('get ls-lR.gz')
child.expect('ftp> ')
child.sendline ('bye')

emacs下配置python开发环境

  1. 安装Pymacs, http://pymacs.progiciels-bpi.ca/pymacs.html
1
sudo python setup.py install
  1. 安装ropemode, http://pypi.python.org/pypi/ropemode
1
sudo python setup.py install
  1. 安装ropemacs,http://rope.sourceforge.net/ropemacs.html
1
sudo python setup.py install
  1. 在.emacs中加入
1
2
3
(autoload 'pymacs-apply "pymacs")(autoload 'pymacs-call "pymacs")(autoload 'pymacs-eval "pymacs" nil t)(autoload 'pymacs-exec "pymacs" nil t)(autoload 'pymacs-load "pymacs" nil t)

(pymacs-load "ropemacs" "rope-")(setq ropemacs-enable-autoimport t)

ubuntu下安装telnet服务器

  1. 安装xinetd和telnetd
1
sudo apt-get install xinetd telnetd
  1. /etc/inetd.conf在安装过程中已经配置好,修改/etc/xinetd.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
defaults{

# Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
## Please note that you need a log_type line to be able to use log_on_success
## and log_on_failure. The default is the following :## log_type = SYSLOG daemon info
# 
## start the insert content
#
# if I have time, I will add some comments about this part.
# instances =60#log_type = SYSLOG authpriv
# log_on_success = HOST PID
# log_on_failure = HOST
# tcps = 25 30
## end the insert content
  1. 添加/etc/xinet.d/telnet
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#service telnet
#{
#disable = no
#flags = REUSE
#socket_type = stream
#wait = no
#user = root
#server = /usr/sbin/in.telnetd
#log_on_failure += USERID
#}
  1. 重启xinetd服务
1
sudo /etc/init.d/xinetd restart
  1. 测试一下
1
telnet 127.0.0.1

android获取手机号码

android下获取手机的号码

1
2
3
4
5
6
7
//创建电话管理
TelephonyManager tm = (TelephonyManager);
//与手机建立连接
activity.getSystemService(Context.TELEPHONY_SERVICE);

//获取手机号码
String phoneId = tm.getLine1Number();

在manifest file中添加

1
2
<!--  记得在manifest file中添加 -->
<uses-permission   android:name="android.permission.READ_PHONE_STATE" />

程序在模拟器上无法获取,必须连接手机

参考连接:

http://hi.baidu.com/hencechen/blog/item/e4d983094c01b4c73ac76349.html

python telnetlib第一例

参考limodou

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import telnetlib

host = {}
host['ip']='127.0.0.1'
host['user']='user'
host['password']='password***'
host['commands']=['cd /home/xxxxx', 'ls -l --color=no']

def do(host):    
    tn = telnetlib.Telnet(host['ip'])
#    tn.set_debuglevel(2)    
    tn.read_until("login: ")    
    tn.write(host['user'] + "n")    
    tn.read_until("Password: ")    
    tn.write(host['password'] + "n")

#    tn.read_all()    

    for command in host['commands']:        
    	tn.write(command+'n')

    tn.write("exit")    
    print tn.read_all()

    print 'Finish!'

do(host)