Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

pylibpcap: python module for libpcap

#!/usr/bin/env python2
import pcap
import sys
import string
import time
import socket
import struct
protocols={socket.IPPROTO_TCP:'tcp',
           socket.IPPROTO_UDP:'udp',
           socket.IPPROTO_ICMP:'icmp'}
def decode_ip_packet(s):
  d={}
  d['version']=(ord(s[0]) & 0xf0) >> 4
  d['header_len']=ord(s[0]) & 0x0f
  d['tos']=ord(s[1])
  d['total_len']=socket.ntohs(struct.unpack('H',s[2:4])[0])
  d['id']=socket.ntohs(struct.unpack('H',s[4:6])[0])
  d['flags']=(ord(s[6]) & 0xe0) >> 5
  d['fragment_offset']=socket.ntohs(struct.unpack('H',s[6:8])[0] & 0x1f)
  d['ttl']=ord(s[8])
  d['protocol']=ord(s[9])
  d['checksum']=socket.ntohs(struct.unpack('H',s[10:12])[0])
  d['source_address']=pcap.ntoa(struct.unpack('i',s[12:16])[0])
  d['destination_address']=pcap.ntoa(struct.unpack('i',s[16:20])[0])
  if d['header_len']>5:
    d['options']=s[20:4*(d['header_len']-5)]
  else:
    d['options']=None
  d['data']=s[4*d['header_len']:]
  return d
def dumphex(s):
  bytes = map(lambda x: '%.2x' % x, map(ord, s))
  for i in xrange(0,len(bytes)/16):
    print '    %s' % string.join(bytes[i*16:(i+1)*16],' ')
  print '    %s' % string.join(bytes[(i+1)*16:],' ')
   
def print_packet(pktlen, data, timestamp):
  if not data:
    return
  if data[12:14]=='\x08\x00':
    decoded=decode_ip_packet(data[14:])
    print '\n%s.%f %s > %s' % (time.strftime('%H:%M',
                                    &nbs


Ïà¹ØÎĵµ£º

python ¶ÁдExcelÎļþ

http://sourceforge.net/projects/pyexcelerator/
12ÔÂ2ÈÕ
python ¶ÁдExcelÎļþ£¨×ªÌû limodou£©
http://www.lexicon.net/sjmachin/xlrd.htm
Õâ¸ö°üÊÇÓÃÀ´¶ÁExcelÎļþµÄ
ÔÚ·¢ÏÖ xlrd Ö®ºó²»¾Ã¾Í·¢ÏÖÁË pyExcelerator
£¬ËüÓë xlrd ²»Í¬£¬ËüÖ÷ÒªÊÇÓÃÀ´Ð´ Excel Îļþ£¬µ±È»¶ÁÒ²ÊÇûÓÐÎÊÌâµÄ¡£ÏÂÃæ¾ÍËüµÄʹÓüòµ¥µØ½éÉ ......

python ×Ö·û´®ºÍdatetimeת»»

       ΪÁË´Ó×Ö·û´®ÖÐÌáȡʱ¼ä£¬²¢½øÐбȽϣ¬Òò´ËÓÐÁËÕâ¸öÎÊÌ⣬ÈçºÎ½«×Ö·û´®×ª»»³ÉdatetimeÀàÐÍ
       1.×Ö·û´®ÓëtimeÀàÐ͵Äת»»
>>> import time
>>> timestr = "time2009-12-14"
>>> t = time.strptime(timest ......

python minidom дxmlʾÀý

ÒÔÏÂÊÇÒ»¸öͨ¹ýminidomÄ£¿éдÎļþµÄÍêÕûʾÀý£¬ÊÇÔÚ×î½ü×öµÄÏîÄ¿WalleÉÏÃæÓõ½µÄ,Õâ¸öʾÀýµÄÄ¿µÄÊÇÉú³ÉÒ»¸öÈçϵĸñʽµÄxml£¬Îļþ¸ñʽΪÎÞBOM utf-8¡£
Éú³ÉxmlÎļþ¸ñʽ£º
<?xml version="1.0" encoding="utf-8"?> 
<coverages> 
    <coverage> 
    ......

ʹÓÃpython²Ù×÷´®¿Ú

Ò»¡¢
ΪÁËʹÓÃpython²Ù×÷´®¿Ú£¬Ê×ÏÈÐèÒªÏÂÔØÏà¹ØÄ£¿é:
1. pyserial (http://pyserial.wiki.sourceforge.net/pySerial)
2. pywin32 (http://sourceforge.net/projects/pywin32/)
¶þ¡¢
google “python ´®¿Ú ²Ù×÷”¹Ø¼ü×Ö£¬ÕÒµ½Ïà¹Øpython´úÂ룬
ÎÒÊÇ´Óhttp://currentlife.blog.sohu.com/53741351.htmlÒ³ÃæÉÏ ......

pythonѧϰ±Ê¼Ç——pcap×¥°ü

½ñÌì¿´¿´ÈçºÎÓÃpythonʵÏÖ×¥°ü¡£
    ÒÔǰÎÒÃÇÔøÓùýwinpcapʵÏÖ×¥°ü£¬Æäʵ½ñÌìÎÒÃÇ»¹ÊÇÓÃËü£¬Ö»²»¹ýÊÇËüÔÚpythonϵÄÄ£¿é£¬ÔÚÓÃ֮ǰÎÒÃDZØÐëÏÈÏÂÔØÁ½¸ö¿â£¬pcap¿âºÍdpkt¿â£¬Õâ¸ö¿ÉÒÔÔÚGoogle codeÀïºÜÈÝÒ×ÕÒµ½£¬ÐèҪעÒâµÄÊÇpcapÖ»Ö§³Öµ½python2.5 £¬ËùÒÔÎÒÃÇÒªÓÃ2.5À´±àд¡£
    °²×°ÍêÁ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ