Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed to allow IP ranges to be specified. #92

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed to allow IP ranges to be specified.
Useful when client IP addresses may not be known but are within a network range such as the case when using auto scaling load balancers.

To use, simply specify the RemoteHost address as a CIDR.

For example:

hosts={
    'internal': server.RemoteHost('192.168.0.0/24', 'Kah3choteereethiejeimaeziecumi', 'internal'),
    'localnet': server.RemoteHost('10.0.0.0/18', 'Kah3choteereethiejeimaeziecumi', 'localnet'),
    'allhosts': server.RemoteHost('0/0', 'Kah3choteereethiejeimaeziecumi', 'default'),
    'onehost': server.RemoteHost('10.0.0.1', 'Kah3choteereethiejeimaeziecumi', 'onehost'),
}
salway committed Sep 9, 2018
commit 057fe1232e348b70d16b12ba77c9d0e49fabe424
2 changes: 1 addition & 1 deletion pyrad/server.py
Original file line number Diff line number Diff line change
@@ -199,7 +199,7 @@ def _get_remote_host(self, ip):
:type ip: String
"""
all_hosts = None
ip_addr = IPAddress(socket.gethostbyname(ip))
ip_addr = IPAddress(ip)
for ref, host in self.hosts.items():
if ip_addr in IPNetwork(host.address):
return host
6 changes: 3 additions & 3 deletions pyrad/tests/testServer.py
Original file line number Diff line number Diff line change
@@ -187,13 +187,13 @@ def HandleAuthPacket(self, pkt):
class AcctPacketHandlingTests(unittest.TestCase):
def setUp(self):
self.server = Server()
self.server.hosts['host'] = RemoteHost('127.0.0.1', 'supersecret', 'name')
self.server.hosts['host'] = RemoteHost('10.0.0.0/24', 'supersecret', 'name')
self.packet = TrivialObject()
self.packet.code = AccountingRequest
self.packet.source = ('127.0.0.1', 'port')
self.packet.source = ('10.0.0.1', 'port')

def testHandleAcctPacketUnknownHost(self):
self.packet.source = ('127.0.0.2', 'port')
self.packet.source = ('10.1.0.1', 'port')
try:
self.server._HandleAcctPacket(self.packet)
except ServerPacketError as e: