Created
August 2, 2018 11:50
-
-
Save mkvenkit/1cdf0ce8c2f2095266b245e9013fe12c to your computer and use it in GitHub Desktop.
Convert from ipv4 a.b.c.d to ipv6 abcd:abcd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################################################### | |
| # to_ipv6.py | |
| # | |
| # Author: electronut.in | |
| # | |
| # Description: | |
| # | |
| # Convert from ipv4 to ipv6 | |
| # eg: | |
| # | |
| # python to_ipv6.py 185.199.108.153 | |
| # | |
| # b9c7:6c99 | |
| # | |
| ############################################################################### | |
| import sys | |
| def to_ipv6(a): | |
| b = "".join([format(int(x), '02x') for x in a.split(".")]) | |
| return b[0:4] + ":" + b[4:] | |
| # main() function | |
| def main(): | |
| # use sys.argv if needed | |
| if len(sys.argv) != 2: | |
| print("usage: python to_ipv6.py a.b.c.d") | |
| else: | |
| print(to_ipv6(sys.argv[1])) | |
| # call main | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment