mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Basic RADIUS support - checkpoint
This commit is contained in:
parent
3d1fd6ca5e
commit
9e0b0f9187
15 changed files with 928 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
##! Functions for parsing and manipulating IP addresses.
|
||||
##! Functions for parsing and manipulating IP and MAC addresses.
|
||||
|
||||
# Regular expressions for matching IP addresses in strings.
|
||||
const ipv4_addr_regex = /[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/;
|
||||
|
@ -119,3 +119,27 @@ function addr_to_uri(a: addr): string
|
|||
else
|
||||
return fmt("[%s]", a);
|
||||
}
|
||||
|
||||
## Given a string, extracts the hex digits and returns a MAC address in the
|
||||
## format: 00:a0:32:d7:81:8f. If the string doesn't contain 12 or 16 hex digits,
|
||||
## an empty string is returned.
|
||||
##
|
||||
## a: the string to normalize
|
||||
##
|
||||
## Returns: a normalized MAC address, or an empty string in the case of an error.
|
||||
function normalize_mac(a: string): string
|
||||
{
|
||||
local result = to_lower(gsub(a, /[^A-Fa-f0-9]/, ""));
|
||||
local octets: string_vec;
|
||||
if ( |result| == 12 )
|
||||
{
|
||||
octets = str_split(result, vector(2, 4, 6, 8, 10));
|
||||
return fmt("%s:%s:%s:%s:%s:%s", octets[1], octets[2], octets[3], octets[4], octets[5], octets[6]);
|
||||
}
|
||||
if ( |result| == 16 )
|
||||
{
|
||||
octets = str_split(result, vector(2, 4, 6, 8, 10, 12, 14));
|
||||
return fmt("%s:%s:%s:%s:%s:%s:%s:%s", octets[1], octets[2], octets[3], octets[4], octets[5], octets[6], octets[7], octets[8]);
|
||||
}
|
||||
return "";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue