Skip to content

Commit

Permalink
🗓 Aug 20, 2022 10:30:04 AM
Browse files Browse the repository at this point in the history
✨ int_to_ip
  • Loading branch information
securisec committed Aug 20, 2022
1 parent 3a417c1 commit 7b4a6f0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Misc:
☐ cyberchef recipe to chepy recipe converter

Archive:
✔ ip from int and vice versa @project(New ideas)
✔ subsection. regex select from state and run all subsequent operations on the selected data @project(New ideas)
✔ base 91 @project(Methods)
✔ remove unprintable method @project(New ideas)
Expand Down
26 changes: 26 additions & 0 deletions chepy/modules/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,29 @@ def get_ssl_cert(self, port: int = 443) -> NetworkingT:
final[key] = cert[key]
self.state = final
return self

@ChepyDecorators.call_stack
def int_to_ip(self) -> NetworkingT:
"""Convert an integer to an IP address
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy(3232235777).int_to_ip().o
"""
self.state = str(ipaddress.ip_address(self._convert_to_int()))
return self

@ChepyDecorators.call_stack
def ip_to_int(self) -> NetworkingT:
"""Convert an integer to an IP address
Returns:
Chepy: The Chepy object.
Examples:
>>> Chepy(3232235777).int_to_ip().o
"""
self.state = int(ipaddress.ip_address(self._convert_to_str()))
return self
2 changes: 2 additions & 0 deletions chepy/modules/networking.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class Networking(ChepyCore):
def parse_uri(self: NetworkingT) -> NetworkingT: ...
def parse_ip_range(self: NetworkingT) -> NetworkingT: ...
def parse_ipv6(self: NetworkingT) -> NetworkingT: ...
def int_to_ip(self: NetworkingT) -> NetworkingT: ...
def ip_to_int(self: NetworkingT) -> NetworkingT: ...
def get_ssl_cert(self: NetworkingT, port: int=...) -> NetworkingT: ...
4 changes: 4 additions & 0 deletions tests/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ def test_parse_ipv6():
def test_get_cert():
assert Chepy("google.com").get_ssl_cert().o["subject"]["commonName"] != ""


def test_int_to_ip():
assert Chepy("2130706433").int_to_ip().o == "127.0.0.1"
assert Chepy("127.0.0.1").ip_to_int().o == 2130706433

0 comments on commit 7b4a6f0

Please sign in to comment.