Perl and Python FreeRadius client

2006阅读 0评论2011-12-02 huhuegg
分类:Python/Ruby

perl client for freeradius
  1. #!/usr/bin/perl
  2. use strict;
  3. use Authen::Radius;

  4. my $RadiusIP="192.168.56.101";
  5. my $RadiusKey="pterm_radius_56";
  6. my $r=new Authen::Radius(Host=>$RadiusIP,Secret=>$RadiusKey);
  7. if ($r->check_pwd("test","test")) {
  8.     print "ok\n";
  9. } else {
  10.     print "err\n";
  11. }
 
python client for freeradius
  1. #!/usr/bin/env python

  2. import pyrad.packet
  3. from pyrad.client import Client
  4. from pyrad.dictionary import Dictionary


  5. srv=Client(server="192.168.56.101",
  6.            secret="pterm_radius_56",
  7.            dict=Dictionary("dictionary"))

  8. req=srv.CreateAuthPacket(code=pyrad.packet.AccessRequest,
  9.                          User_Name="test")

  10. req["User-Password"]=req.PwCrypt("test")

  11. reply=srv.SendPacket(req)
  12. if reply.code==pyrad.packet.AccessAccept:
  13.     print "access accepted"
  14. else:
  15.     print "access denied"
 
dictionary文件
 
  1. #
  2. # Version $Id: dictionary,v 1.1.1.1 2002/10/11 12:25:39 wichert Exp $
  3. #
  4. #    This file contains dictionary translations for parsing
  5. #    requests and generating responses. All transactions are
  6. #    composed of Attribute/Value Pairs. The value of each attribute
  7. #    is specified as one of 4 data types. Valid data types are:
  8. #
  9. #    string - 0-253 octets
  10. #    ipaddr - 4 octets in network byte order
  11. #    integer - 32 bit value in big endian order (high byte first)
  12. #    date - 32 bit value in big endian order - seconds since
  13. #                    00:00:00 GMT, Jan. 1, 1970
  14. #
  15. #    FreeRADIUS includes extended data types which are not defined
  16. #    in RFC 2865 or RFC 2866. These data types are:
  17. #
  18. #    abinary - Ascend
上一篇:Python Ubuntu下建立TurboGears2环境
下一篇:Ubuntu 解决fcitx小方格"乱码"问题