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第三方库


热门话题
JavaGCP:一个VM可以位于具有相同地址的不同网络上吗?   java查找安卓中第一个数组的第二个数组中存在的元素的索引   java摄像头活动不工作,设置参数失败   用于python的Base64转换的Java等效代码   为什么JPA/Hibernate在我尝试运行@Query时抛出“java.lang.NegativeArraySizeException:1”?   如何在ubuntu for java的终端上设置路径?   java为什么这两个IP不同?   java JPA:如何将本机查询结果集转换为POJO类集合   java如何在|(12)|(23)中用数字拆分字符串   异常处理如何让程序在达到Java目标后停止运行   java如何不添加以特定字符开头的元素   java如何通过字符串获得swing按钮名称?   java如何在响应不成功时读取改装中的错误体?   java*更新*现在我的程序可以编译但不运行了?