blob: 10a9abdbcd60fa06fc313c74b7db747e8f26d008 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
from ryu.lib import addrconv
def ipv4_to_bin(ip):
'''
Parse an IP address and return an unsigned int.
The IP address is in dotted decimal notation.
'''
return addrconv.ipv4.text_to_bin(ip)
def ipv4_to_str(ip):
"""Generate IP address string from an unsigned int.
ip: unsigned int of form w << 24 | x << 16 | y << 8 | z
returns: ip address string w.x.y.z"""
return addrconv.ipv4.bin_to_text(ip)
def ipv6_to_bin(ipv6):
'''
convert ipv6 string to binary representation
'''
return addrconv.ipv6.text_to_bin(ipv6)
def ipv6_to_str(bin_addr):
'''
convert binary representation to human readable string
'''
return addrconv.ipv6.bin_to_text(bin_addr)
|