Initial commit

This commit is contained in:
Istvan Ruzman
2020-07-02 16:01:29 +02:00
commit 6b639f3aaf
65 changed files with 7298 additions and 0 deletions

51
example/coa.py Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import sys
from os import path
import pyrad.packet
from pyrad.client import Client
from pyrad.dictionary import Dictionary
def main(path_to_dictionary, coa_type, nas_identifier):
# create coa client
client = Client(server='127.0.0.1',
secret=b'Kah3choteereethiejeimaeziecumi',
dict=Dictionary(path_to_dictionary))
# set coa timeout
client.timeout = 30
# create coa request packet
attributes = {
'Acct-Session-Id': '1337',
'NAS-Identifier': nas_identifier,
}
if coa_type == 'coa':
# create coa request
request = client.CreateCoAPacket(**attributes)
elif coa_type == 'dis':
# create disconnect request
request = client.CreateCoAPacket(
code=pyrad.packet.DisconnectRequest,
**attributes)
else:
sys.exit(1)
# send request
result = client.SendPacket(request)
print(result)
print(result.code)
if __name__ == '__main__':
if len(sys.argv) != 3:
print('usage: coa.py {coa|dis} daemon-1234')
sys.exit(1)
dictionary = path.join(path.dirname(path.abspath(__file__)), 'dictionary')
main(dictionary, sys.argv[1], sys.argv[2])