小编tho*_*hor的帖子

如何在Python中配置到syslog的日志记录?

我无法理解Python的logging模块.我的需求非常简单:我只想将所有内容记录到syslog中.阅读文档后,我想出了这个简单的测试脚本:

import logging
import logging.handlers

my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler()

my_logger.addHandler(handler)

my_logger.debug('this is debug')
my_logger.critical('this is critical')
Run Code Online (Sandbox Code Playgroud)

但是此脚本不会在syslog中生成任何日志记录.怎么了?

python logging syslog

113
推荐指数
8
解决办法
12万
查看次数

用Scapy解析PPPoE标签

我试图用Scapy正确剖析PPPoE Discovery数据包.以下是Scapy如何显示示例PADI数据包:

>>> p = Ether("\xff\xff\xff\xff\xff\xff\x08\x00'\xf3<5\x88c\x11\t\x00\x00\x00\x0c\x01\x01\x00\x00\x01\x03\x00\x04\xe0\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
>>> p.show()
 ###[ Ethernet ]###
  dst= ff:ff:ff:ff:ff:ff
  src= 08:00:27:f3:3c:35
  type= 0x8863
###[ PPP over Ethernet Discovery ]###
     version= 1L
     type= 1L
     code= PADI
     sessionid= 0x0
     len= 12
###[ Raw ]###
        load= '\x01\x01\x00\x00\x01\x03\x00\x04\xe0\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Run Code Online (Sandbox Code Playgroud)

我想解析Raw有效负载.此有效负载只是一个PPPoE标记列表.每个标签由两个字节的代码字段,两个字节长度的字段和一个值组成(当然,它是由前一个字段给出的长度).

这是我尝试代表所有这些:

from scapy.all import *

class PPPoETag(Packet):
    name = "PPPoE Tag"
    fields_desc = [ ShortEnumField('tag_type', None,
                                   {0x0000: 'End-Of-List',
                                    0x0101: 'Service-Name',
                                    0x0102: 'AC-Name',
                                    0x0103: 'Host-Uniq',
                                    0x0104: 'AC-Cookie',
                                    0x0105: 'Vendor-Specific',
                                    0x0110: 'Relay-Session-Id',
                                    0x0201: 'Service-Name-Error',
                                    0x0202: 'AC-System-Error',
                                    0x0203: 'Generic-Error'}),
                    FieldLenField('tag_len', None, length_of='tag_value', fmt='H'),
                    StrLenField('tag_value', …
Run Code Online (Sandbox Code Playgroud)

python scapy pppoe

11
推荐指数
1
解决办法
2219
查看次数

如何在TCL中删除字符串中的空格?

我需要从TCL中的字符串中删除前导和尾随空格.怎么样?

string whitespace tcl

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×2

logging ×1

pppoe ×1

scapy ×1

string ×1

syslog ×1

tcl ×1

whitespace ×1