IP addresses are moved around in a native format, called a ComboAddress. ComboAddresses can be IPv4 or IPv6, and unless you want to know, you don’t need to.
ComboAddress¶newCA(address) → ComboAddress¶Returns a new ComboAddress object based on address
| Parameters: | address (string) – The IP address, with optional port, to represent |
|---|
addr = newCA("1.2.3.4")
newCAFromRaw(rawaddress[, port]) → ComboAddress¶Returns a new ComboAddress object based on the 4- or 16-octet string.
For example, newCAFromRaw('ABCD') makes a ComboAddress object holding the IP 65.66.67.68, because those are the ASCII values for those four letters.
| Parameters: |
|
|---|
ComboAddress¶A ComboAddress represents an IP address with possibly a port number.
The object can be an IPv4 or an IPv6 address.
It has these methods:
ComboAddress:getPort() -> intReturns the port number.
ComboAddress:isIPv4() -> boolReturns true if the address is an IPv4, false otherwise
ComboAddress:isIPv6() -> boolReturns true if the address is an IPv6, false otherwise
ComboAddress:isMappedIPv4() -> boolReturns true if the address is an IPv4 mapped into an IPv6, false otherwise
ComboAddress:mapToIPv4() -> ComboAddressConvert an IPv4 address mapped in a v6 one into an IPv4. Returns a new ComboAddress
ComboAddress:toString() -> stringReturns in human-friendly format
ComboAddress:getRaw() -> stringReturns in raw bytes format
ComboAddress:toStringWithPort() -> stringReturns in human-friendly format, with port number
ComboAddress:truncate(bits)Truncate the ComboAddress to the specified number of bits.
This essentially zeroes all bits after bits.
| Parameters: | bits (int) – Amount of bits to truncate to |
|---|
We provide a convenient object class that can store unique ComboAddresses in no particular order and allows fast retrieval of individual elements based on their values
addr = newCA("1.2.3.4")
myset = newCAS()
myset:add(addr)
if myset:check(addr) then -- prints "found!"
print('found!')
end
ComboAddressSet¶newCAS() → ComboAddressSet¶Returns an empty ComboAddressSet object
ComboAddressSet¶A ComboAddressSet can store multiple ComboAddress
It has these methods:
ComboAddressSet:add(addr)ComboAddressSet:add(addrs)ComboAddressSet:add(ca)Add the given addresses to set. the parameter can be of the following types:
| Parameters: |
|
|---|
addr = newCA("1.2.3.4")
myset = newCAS()
myset:add(addr)
myset:add("5.6.7.8")
myset:add({"::1/128", "10.11.12.13"})