Skip to content

Host

Host

Generic RADIUS capable host.

Source code in pyrad2/host.py
class Host:
    """Generic RADIUS capable host."""

    def __init__(
        self,
        authport: int = 1812,
        acctport: int = 1813,
        coaport: int = 3799,
        dict: Optional[Dictionary] = None,
    ):
        """Initializes a host.

        Args:
            authport (int): port to listen on for authentication packets
            acctport (int): port to listen on for accounting packets
            coaport (int): port to listen on for CoA packets
            dict (Dictionary): RADIUS dictionary
        """
        self.dict = dict
        self.authport = authport
        self.acctport = acctport
        self.coaport = coaport

    def CreatePacket(self, **args) -> packet.Packet:
        """Create a new RADIUS packet.
        This utility function creates a new RADIUS authentication
        packet which can be used to communicate with the RADIUS server
        this client talks to. This is initializing the new packet with
        the dictionary and secret used for the client.

        Returns:
            pyrad2.packet.Packet: A new empty packet instance.
        """
        return packet.Packet(dict=self.dict, **args)

    def CreateAuthPacket(self, **args) -> packet.Packet:
        """Create a new authentication RADIUS packet.
        This utility function creates a new RADIUS authentication
        packet which can be used to communicate with the RADIUS server
        this client talks to. This is initializing the new packet with
        the dictionary and secret used for the client.

        Returns:
            pyrad2.packet.Packet: A new empty packet instance.
        """
        return packet.AuthPacket(dict=self.dict, **args)

    def CreateAcctPacket(self, **args) -> packet.Packet:
        """Create a new accounting RADIUS packet.
        This utility function creates a new accounting RADIUS packet
        which can be used to communicate with the RADIUS server this
        client talks to. This is initializing the new packet with the
        dictionary and secret used for the client.

        Returns:
            packet.Packet: A new empty packet instance.
        """
        return packet.AcctPacket(dict=self.dict, **args)

    def CreateCoAPacket(self, **args) -> packet.Packet:
        """Create a new CoA RADIUS packet.
        This utility function creates a new CoA RADIUS packet
        which can be used to communicate with the RADIUS server this
        client talks to. This is initializing the new packet with the
        dictionary and secret used for the client.

        Returns:
            packet.Packet: A new empty packet instance.
        """
        return packet.CoAPacket(dict=self.dict, **args)

    def SendPacket(self, fd: socket.socket, pkt) -> None:
        """Send a packet.

        Args:
            fd (socket.socket): Socket to send packet with
            pkt (packet.Packet): The packet instance
        """
        fd.sendto(pkt.Packet(), pkt.source)

    def SendReplyPacket(self, fd: socket.socket, pkt: packet.Packet) -> None:
        """Send a packet.

        Args:
            fd (socket.socket): Socket to send packet with
            pkt (packet.Packet): The packet instance
        """
        fd.sendto(pkt.ReplyPacket(), pkt.source)  # type: ignore

__init__(authport=1812, acctport=1813, coaport=3799, dict=None)

Initializes a host.

Parameters:

Name Type Description Default
authport int

port to listen on for authentication packets

1812
acctport int

port to listen on for accounting packets

1813
coaport int

port to listen on for CoA packets

3799
dict Dictionary

RADIUS dictionary

None
Source code in pyrad2/host.py
def __init__(
    self,
    authport: int = 1812,
    acctport: int = 1813,
    coaport: int = 3799,
    dict: Optional[Dictionary] = None,
):
    """Initializes a host.

    Args:
        authport (int): port to listen on for authentication packets
        acctport (int): port to listen on for accounting packets
        coaport (int): port to listen on for CoA packets
        dict (Dictionary): RADIUS dictionary
    """
    self.dict = dict
    self.authport = authport
    self.acctport = acctport
    self.coaport = coaport

CreatePacket(**args)

Create a new RADIUS packet. This utility function creates a new RADIUS authentication packet which can be used to communicate with the RADIUS server this client talks to. This is initializing the new packet with the dictionary and secret used for the client.

Returns:

Type Description
Packet

pyrad2.packet.Packet: A new empty packet instance.

Source code in pyrad2/host.py
def CreatePacket(self, **args) -> packet.Packet:
    """Create a new RADIUS packet.
    This utility function creates a new RADIUS authentication
    packet which can be used to communicate with the RADIUS server
    this client talks to. This is initializing the new packet with
    the dictionary and secret used for the client.

    Returns:
        pyrad2.packet.Packet: A new empty packet instance.
    """
    return packet.Packet(dict=self.dict, **args)

CreateAuthPacket(**args)

Create a new authentication RADIUS packet. This utility function creates a new RADIUS authentication packet which can be used to communicate with the RADIUS server this client talks to. This is initializing the new packet with the dictionary and secret used for the client.

Returns:

Type Description
Packet

pyrad2.packet.Packet: A new empty packet instance.

Source code in pyrad2/host.py
def CreateAuthPacket(self, **args) -> packet.Packet:
    """Create a new authentication RADIUS packet.
    This utility function creates a new RADIUS authentication
    packet which can be used to communicate with the RADIUS server
    this client talks to. This is initializing the new packet with
    the dictionary and secret used for the client.

    Returns:
        pyrad2.packet.Packet: A new empty packet instance.
    """
    return packet.AuthPacket(dict=self.dict, **args)

CreateAcctPacket(**args)

Create a new accounting RADIUS packet. This utility function creates a new accounting RADIUS packet which can be used to communicate with the RADIUS server this client talks to. This is initializing the new packet with the dictionary and secret used for the client.

Returns:

Type Description
Packet

packet.Packet: A new empty packet instance.

Source code in pyrad2/host.py
def CreateAcctPacket(self, **args) -> packet.Packet:
    """Create a new accounting RADIUS packet.
    This utility function creates a new accounting RADIUS packet
    which can be used to communicate with the RADIUS server this
    client talks to. This is initializing the new packet with the
    dictionary and secret used for the client.

    Returns:
        packet.Packet: A new empty packet instance.
    """
    return packet.AcctPacket(dict=self.dict, **args)

CreateCoAPacket(**args)

Create a new CoA RADIUS packet. This utility function creates a new CoA RADIUS packet which can be used to communicate with the RADIUS server this client talks to. This is initializing the new packet with the dictionary and secret used for the client.

Returns:

Type Description
Packet

packet.Packet: A new empty packet instance.

Source code in pyrad2/host.py
def CreateCoAPacket(self, **args) -> packet.Packet:
    """Create a new CoA RADIUS packet.
    This utility function creates a new CoA RADIUS packet
    which can be used to communicate with the RADIUS server this
    client talks to. This is initializing the new packet with the
    dictionary and secret used for the client.

    Returns:
        packet.Packet: A new empty packet instance.
    """
    return packet.CoAPacket(dict=self.dict, **args)

SendPacket(fd, pkt)

Send a packet.

Parameters:

Name Type Description Default
fd socket

Socket to send packet with

required
pkt Packet

The packet instance

required
Source code in pyrad2/host.py
def SendPacket(self, fd: socket.socket, pkt) -> None:
    """Send a packet.

    Args:
        fd (socket.socket): Socket to send packet with
        pkt (packet.Packet): The packet instance
    """
    fd.sendto(pkt.Packet(), pkt.source)

SendReplyPacket(fd, pkt)

Send a packet.

Parameters:

Name Type Description Default
fd socket

Socket to send packet with

required
pkt Packet

The packet instance

required
Source code in pyrad2/host.py
def SendReplyPacket(self, fd: socket.socket, pkt: packet.Packet) -> None:
    """Send a packet.

    Args:
        fd (socket.socket): Socket to send packet with
        pkt (packet.Packet): The packet instance
    """
    fd.sendto(pkt.ReplyPacket(), pkt.source)  # type: ignore