【发布时间】:2013-04-01 06:32:47
【问题描述】:
我在 radius 中使用 rlm_python 模块,它以十六进制或二进制格式从 coovachilli 获取 DHCP 位置 option82。
将其作为字符串捕获显示为该值\001\027\002\025\001+\001\024,但看起来python显示的值已被截断,因为option82包含TLVs-type,length,values中编码的suboptions,这意味着该字段以0x01(circuit ID, per RFC 3046)类型开头,后跟一个字节的长度。
知道我怎样才能捕捉到这一点并正确解压缩选项吗?
我已经使用struct.unpack 解压缩了字符串,但没有意义..因为它没有说明option82 字段中的压缩suboptions。
Python 2.4.3 (#1, May 5 2011, 16:39:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from struct import *
>>> unpack('=hhl',"\001\027\002\025\001+\001\024" )
(5889, 5378, 335620865)
有什么想法吗?
更新:
Coovachilli 使用 --locationopt82 编译,并将位置作为属性发送,类似这样...
rad_recv: Accounting-Request packet from host 10.66.53.49 port 53178, id=101, length=342
ChilliSpot-Version = "1.3.0"
ChilliSpot-Acct-View-Point = ChilliSpot-Client-View-Point
Event-Timestamp = "Apr 18 2013 11:59:16 BST"
User-Name = "3C-D0-F8-4A-05-68"
Acct-Input-Octets = 0
Acct-Output-Octets = 22851
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 0
Acct-Output-Packets = 370
Acct-Session-Time = 5401
ChilliSpot-Session-State = Authorized
Acct-Status-Type = Interim-Update
Acct-Session-Id = "516fbceb00000002"
Framed-IP-Address = 10.75.33.46
NAS-Port-Type = Wireless-802.11
NAS-Port = 2
NAS-Port-Id = "00000002"
Calling-Station-Id = "3C-D0-F8-4A-05-68"
Called-Station-Id = "00-50-56-B7-66-00"
NAS-IP-Address = 10.75.32.7
ChilliSpot-Location = "\001\030\002\026\001+\001\024"
ChilliSpot-Location-Change-Count = 15
NAS-Identifier = "VLAN299-REGENT"
WISPr-Location-ID = "isocc=GR,cc=44,ac=01200,network=mywifi,my_Network_regent"
WISPr-Location-Name = "REGENT"
freeradius 有 rlm_python 模块,用于查找记帐请求
def accounting(p):
file = open("/tmp/test.log","a")
username = None
chillilocation = None
output = StringIO.StringIO()
for t in p:
if t[0] == 'User-Name':
username = t[1]
elif t[0] == 'ChilliSpot-Location':
chillilocation = t[1]a
output.write(t[1])
content = output.getvalue()
file.write("I am being called in radius accouting section as %s and location is %s \n" % (username,content))
file.close()
print "---Accounting---"
radiusd.radlog(radiusd.L_INFO, '*** radlog call in accounting (0) ***')
print
print p
return radiusd.RLM_MODULE_OK
我已尝试将 ChilliSpot-Location 存储在 string 和 stringIO 中,使用 struct 解压但无济于事,它看起来像是 TLV 格式...
有什么办法可以去掉吗?
【问题讨论】:
-
如何使用 rlm_python 和 coovachilli 将值作为字符串捕获?
-
我已经在上面更新了
-
不确定整个事情,但
ChilliSpot-Location应该是人类可读的字符串。见specs和an example(向下浏览到中间的某个地方,上面写着RADIUS Access-Request from CoovaChilli)