pyrad.host – RADIUS host definition

Base class with the settings shared by RADIUS clients and servers.

class pyrad.host.Host(authport=1812, acctport=1813, coaport=3799, dict=None)[source]

Generic RADIUS capable host.

Base class of pyrad.client.Client and pyrad.server.Server, which holds the dictionary and the ports and creates packets with this dictionary.

Variables:
  • dict – RADIUS dictionary

  • authport – the port a server listens on for authentication packets, or the port of the server a client sends them to

  • acctport – the port a server listens on for accounting packets, or the port of the server a client sends them to

  • coaport – the port a server listens on for CoA and Disconnect packets, or the port of the server a client sends them to

Parameters:
  • authport (int) – authentication port, see authport

  • acctport (int) – accounting port, see acctport

  • coaport (int) – CoA port, see coaport

  • dict (pyrad.dictionary.Dictionary) – RADIUS dictionary

CreateAcctPacket(**args)[source]

Create an accounting packet with the dictionary of this host.

The keyword arguments are passed to pyrad.packet.AcctPacket: packet arguments (code, id, secret, authenticator, message_authenticator, packet) and attributes to add, with - in the attribute names replaced by _. The default code is Accounting-Request.

Returns:

a new packet

Return type:

pyrad.packet.AcctPacket

CreateAuthPacket(**args)[source]

Create an authentication packet with the dictionary of this host.

The keyword arguments are passed to pyrad.packet.AuthPacket: packet arguments (code, id, secret, authenticator, auth_type, message_authenticator, packet) and attributes to add, with - in the attribute names replaced by _ (User_Name='alice'). The default code is Access-Request.

Returns:

a new packet

Return type:

pyrad.packet.AuthPacket

CreateCoAPacket(**args)[source]

Create a CoA or Disconnect packet with the dictionary of this host.

The keyword arguments are passed to pyrad.packet.CoAPacket: packet arguments (code, id, secret, authenticator, message_authenticator, packet) and attributes to add, with - in the attribute names replaced by _. The default code is CoA-Request, pass code=pyrad.packet.DisconnectRequest for a Disconnect-Request.

Returns:

a new packet

Return type:

pyrad.packet.CoAPacket

CreatePacket(**args)[source]

Create a generic RADIUS packet with the dictionary of this host.

The keyword arguments are passed to pyrad.packet.Packet: packet arguments such as code, id, secret, authenticator or packet, and attributes to add, with - in the attribute names replaced by _.

Returns:

a new packet

Return type:

pyrad.packet.Packet

SendPacket(fd, pkt)[source]

Send a request packet to the address in pkt.source.

The packet is encoded with pkt.RequestPacket(). pyrad doesn’t use this method itself; pyrad.client.Client.SendPacket() replaces it.

Parameters:
  • fd (socket.socket) – socket to send the packet with

  • pkt (pyrad.packet.Packet) – packet to send

SendReplyPacket(fd, pkt)[source]

Send a reply packet to the address in pkt.source.

The packet is encoded with pyrad.packet.Packet.ReplyPacket(). A reply created with CreateReply of a received request has the source of the request.

Parameters:
  • fd (socket.socket) – socket to send the packet with

  • pkt (pyrad.packet.Packet) – reply packet to send