MCPcopy Create free account
hub / github.com/Cryptogenic/PS5-IPV6-Kernel-Exploit / _explode_shorthand_ip_string

Function _explode_shorthand_ip_string

fakedns.py:83–121  ·  view source on GitHub ↗

Expand a shortened IPv6 address. Args: ip_str: A string, the IPv6 address. Returns: A string, the expanded IPv6 address.

(ip_str)

Source from the content-addressed store, hash-verified

81# Stolen:
82# https://github.com/learningequality/ka-lite/blob/master/python-packages/django/utils/ipv6.py#L209
83def _explode_shorthand_ip_string(ip_str):
84 """
85 Expand a shortened IPv6 address.
86 Args:
87 ip_str: A string, the IPv6 address.
88 Returns:
89 A string, the expanded IPv6 address.
90 """
91 if not _is_shorthand_ip(ip_str):
92 # We've already got a longhand ip_str.
93 return ip_str
94
95 hextet = ip_str.split('::')
96
97 # If there is a ::, we need to expand it with zeroes
98 # to get to 8 hextets - unless there is a dot in the last hextet,
99 # meaning we're doing v4-mapping
100 if '.' in ip_str.split(':')[-1]:
101 fill_to = 7
102 else:
103 fill_to = 8
104
105 if len(hextet) > 1:
106 sep = len(hextet[0].split(':')) + len(hextet[1].split(':'))
107 new_ip = hextet[0].split(':')
108
109 for _ in range(fill_to - sep):
110 new_ip.append('0000')
111 new_ip += hextet[1].split(':')
112
113 else:
114 new_ip = ip_str.split(':')
115
116 # Now need to make sure every hextet is 4 lower case characters.
117 # If a hextet is < 4 characters, we've got missing leading 0's.
118 ret_ip = []
119 for hextet in new_ip:
120 ret_ip.append(('0' * (4 - len(hextet)) + hextet).lower())
121 return ':'.join(ret_ip)
122
123
124def _get_question_section(query):

Callers 1

__init__Method · 0.85

Calls 1

_is_shorthand_ipFunction · 0.85

Tested by

no test coverage detected