Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

如何实现python和telnet通信?

6 views
Skip to first unread message

��ʵ��ë��

unread,
May 26, 2009, 4:17:06 AM5/26/09
to
˼���˺ü���
����һ�� ˮľ��վ����
--
����֮�ϣ���ľΪ�٣����֮�䣬����ʳ»�����Ĺ���֮��������������ū���ϥ֮ͽ���׷ױ����������������ڸ����ڡ�������塷�ھ�ʮ��أ��������˹۵㣬�������ʣ�����ϵ���ߣ�����ץ����л���ʡ����ʡ��Դ��


[m [34m�� ��Դ:��ˮľ���� http://newsmth.net��[FROM: 60.63.77.*] [m

�������µ��dz�

unread,
May 26, 2009, 4:24:09 AM5/26/09
to
�տ�ʼ��python��ʱ��д�ij��򣬱��󵼡���

#!/usr/bin/env python
# -*- coding: gbk -*-

import re
import telnetlib
import time

def loginBBS():
user = "xx"
password = "xxx"
tn = telnetlib.Telnet("bbs.newsmth.net")
# tn.set_debuglevel(1)
tn.read_until("��������:")
time.sleep(1)
tn.write(user + "\n")
tn.read_until("����������:")
time.sleep(1)
tn.write(password + "\n")
for i in range(5):
tn.write("\n")
tn.read_very_eager()
time.sleep(1)
time.sleep(1)
time.sleep(1)
tn.write("eq")
tn.read_until("S) ѡ���Ķ�������")
time.sleep(1)
return tn

def readBoard(tn):
tn.write("s\n")
tn.read_until("��������������� ")
time.sleep(1)
tn.write("ticket\n")
tn.write("$")
tn.read_until("[һ��ģʽ] ")
tn.read_until("\x1b[m")
postlist = tn.read_very_eager()
info = search(postlist)
if info:
msg(tn, info)
# unread = re.search('(\s+\d+ \* .*)', postlist)
# if unread:
# print unread.group()
while re.search(' \* ', postlist):
tn.write("P")
postlist = tn.read_very_eager()
info = search(postlist)
if info:
msg(tn, info)
time.sleep(1)
tn.write("$")
tn.read_very_eager()
time.sleep(1)
tn.write("c")
tn.read_very_eager()
time.sleep(1)
tn.write("e")

def logout(tn):
tn.read_until("G) �뿪ˮľ")
tn.write("g\n")
tn.read_until("�뿪��BBSվ")
tn.write("\n")
time.sleep(1)
tn.write("\n")
tn.read_all
tn.close()

def loop():
tn = loginBBS()
while 1:
time.sleep(60)
readBoard(tn)
logout(tn)


�� �� python818 (��ʵ��ë��) �Ĵ������ᵽ: ��
: ˼���˺ü���
: ����һ�� ˮľ��վ����


--
For every action, there is an equal and opposite criticism.
Never do card tricks for the group you play poker with.
No one is listening until you make a mistake.
The colder the X-ray table, the more of your body is required on it
The severity of the itch is proportional to the reach.
To steal ideas from one person is plagiarism; to steal from many is research.


[36m�� �޸�:��xxxss �� May 26 16:24:08 2009 �޸ı��ġ�[FROM: 211.99.222.*] [m
[m [1;34m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 211.99.222.*] [m

ƽ���Ľ���ʧ��

unread,
May 26, 2009, 4:21:18 AM5/26/09
to
pexpect

�� �� python818 (��ʵ��ë��) �Ĵ������ᵽ: ��
: ˼���˺ü���
: ����һ�� ˮľ��վ����


--
[1;31m�c��
[1;32m�c�ʥ� �ȥ� �f�u�c �c�� �Τ� �c/ ����
[1;33m �� ���� �� �� ���' �̩��� /�� �թ��f
[1;34m �� ���� �` ��


[m [1;31m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 221.221.145.*] [m

����

unread,
May 26, 2009, 5:06:13 AM5/26/09
to
ֱ����cterm�Ľӿڣ�

�� �� python818 (��ʵ��ë��) �Ĵ������ᵽ: ��
: ˼���˺ü���
: ����һ�� ˮľ��վ����


--
���������� �񽿾���� ���������� ��ϴ����ԩ


[m [1;34m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 219.239.50.*] [m

PayPal�Ǹ�������

unread,
May 26, 2009, 5:26:57 AM5/26/09
to
锟较匡拷锟秸诧拷锟斤拷
锟斤拷 锟斤拷 xxxss (锟斤拷锟斤拷锟斤拷锟铰碉拷锟角筹拷) 锟侥达拷锟斤拷锟斤拷锟结到: 锟斤拷
: 锟秸匡拷始锟斤拷python锟斤拷时锟斤拷写锟侥筹拷锟津,憋拷锟襟导★拷锟斤拷
: #!/usr/bin/env python

: # -*- coding: gbk -*-
: ...................

--
[1;30m锟斤拷奴->锟斤拷锟斤拷奴->锟斤拷锟斤拷奴->X61奴->锟斤拷奴->52锟斤拷全锟斤拷锟斤拷奴->锟斤拷锟斤拷M8奴-> [1;34m锟斤拷奴


[m [1;35m锟斤拷 锟斤拷源:锟斤拷水木锟斤拷锟斤拷 newsmth.net锟斤拷[FROM: 219.143.133.*] [m

go

unread,
May 26, 2009, 6:24:58 AM5/26/09
to
�����
������ ID:xx,pwd:xxx��¼˵�������
�� �� xxxss (�������µ��dz�) �Ĵ������ᵽ: ��
: �� ��: Re: ���ʵ��python��telnetͨ�ţ�
: ����վ: ˮľ���� (Tue May 26 16:23:53 2009), ת��
:
: �տ�ʼ��python��ʱ��д�ij��򣬱��󵼡���
:
: #!/usr/bin/env python
: # -*- coding: gbk -*-
:
: import re
: def search(string):
: pattern = '<your pattern here>'
: line = re.search(pattern,string)
: if line:
: print line.group()
: print "\a"
: title = re.search('<detail pattern>',line.group())
: # print title.group()
: return title.group()
: return 0
:
: def msg(tn, message):
: # tn.set_debuglevel(1)
: tn.write("w")
: tn.read_until("��ѶϢ��:")
: tn.write("<someid>\n")
: tn.read_until("�������������ݣ�Ctrl+Q ����:")
: tn.write(message)
: tn.write("\n")
: tn.read_until("ȷ��Ҫ�ͳ���")
: tn.write("y\n")
: # tn.set_debuglevel(0)
:
: def logout(tn):

: tn.read_until("G) �뿪ˮľ")
: tn.write("g\n")
: tn.read_until("�뿪��BBSվ")
: tn.write("\n")
: time.sleep(1)
: tn.write("\n")
: tn.read_all
: tn.close()
:
: def loop():
: tn = loginBBS()
: while 1:
: time.sleep(60)
: readBoard(tn)
: logout(tn)
:
:
: �� �� python818 (��ʵ��ë��) �Ĵ������ᵽ: ��

: : ˼���˺ü���
: : ����һ�� ˮľ��վ����
:
:
: --
: For every action, there is an equal and opposite criticism.

: Never do card tricks for the group you play poker with.
: No one is listening until you make a mistake.
: The colder the X-ray table, the more of your body is required on it
: The severity of the itch is proportional to the reach.
: To steal ideas from one person is plagiarism; to steal from many is research.
:
:
: [36m�� �޸�:��xxxss �� May 26 17:35:46 2009 �޸ı��ġ�[FROM: 211.99.222.*] [m
: [m [1;34m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 211.99.222.*] [m


--

[m [1;33m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 211.99.222.*] [m

�껪ת˲‎

unread,
May 27, 2009, 12:58:54 AM5/27/09
to
ft...
�� �� WarCraFT1 (go) �Ĵ������ᵽ: ��
: �����
: ������ ID:xx,pwd:xxx��¼˵�������


--

[m [1;37m�� ��Դ:��ˮľ���� newsmth.net��[FROM: 218.107.55.*] [m

0 new messages