radius认证模块

py-radius的Python项目详细描述


Travis CI StatusCode Coveragehttps://badge.fury.io/py/py-radius.svg

py半径

用于python 2.7.13+的radius身份验证模块

(c)1999年斯图尔特毕肖普zen@shangri-la.dropbear.id.au>;

这个模块提供了基本的radius客户端功能,允许您的python 针对任何符合RFC2138的RADIUS服务器进行身份验证的代码。

安装

$ pip install py-radius

使用量

radius.py模块可以从命令行运行,提供 RADIUS客户端测试RADIUS服务器:

$ python -m radius
Host [default: 'radius']: radius
Port [default: 1812]: 1812
Enter RADIUS Secret: s3cr3t
Enter your username: foobar
Enter your password: qux
...
Authentication Successful

示例

下面是使用库的示例。

importradiusradius.authenticate(username,password,secret,host='radius',port=1812)# - OR -r=radius.Radius(secret,host='radius',port=1812)print('success'ifr.authenticate(username,password)else'failure')

如果您的radius服务器需要质询/响应,那么使用量会更大一些 复杂。

importradiusr=radius.Radius(secret,host='radius')try:print('success'ifr.authenticate(username,password)else'failure')sys.exit(0)exceptradius.ChallengeResponsease:pass# The ChallengeResponse exception has `messages` and `state` attributes# `messages` can be displayed to the user to prompt them for their# challenge response. `state` must be echoed back as a RADIUS attribute.# Send state as an attribute _IF_ provided.attrs={'State':e.state}ife.stateelse{}# Finally authenticate again using the challenge response from the user# in place of the password.print('success'ifr.authenticate(username,response,attributes=attrs)else'failure')

这个模块有大量的日志记录,可以使用python日志框架来实现。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么数据库中具有“读取”角色的用户不能列出集合?   在Java中使用带有反应式包装器的非阻塞IO逐行读取文件   java当`!`时,什么可以简化表达式应用于`&`或`||`   java Jasperreports报告了四组多个动态图像   java我想将单个字符串的ascii值存储在一行中,如何使用getbyte函数实现这一点   javascript如何在java中写入文件时响应帖子?   新用户注册后java登录失败| Weblogic安全   java中的多线程和同步   java在FOR循环中使用ParseObject   Java货币数字格式   java模拟单例类   java编写大量数据时,部分数据会丢失/当所有数据都存在时,写入过程非常缓慢   java如何处理复合对象的所有子对象?   java如何获得相交集的大小?   我需要在java中的不同源代码中对broadcost Httprequest进行测试   java我想在MainActivity中添加SpreadsheetWebService,而不需要从其他类调用它   安卓 Java是否有NFC API用于标准机器?