• 将IP转换为16进制,用于IPv4-IPv6


    # --*-- coding: utf-8 --*--
    # create by xiaocaiji

    while 1:
    str_ip = input("input a IP:")
    list_ip = str_ip.split('.')
    if len(list_ip) < 4:
    print("error IP")
    x = 0
    try:
    for i in list_ip:
    if int(i) > 256:
    print("error IP")
    x += 1
    elif int(i) < 0 :
    print("error IP")
    x += 1
    except ValueError:
    print("error IP")
    else:
    if x > 0:
    continue
    a = hex(int(list_ip[0]) * 256 + int(list_ip[1]))
    b = hex(int(list_ip[2]) * 256 + int(list_ip[3]))
    a_new = a.replace('0x','')
    b_new = b.replace('0x','')
    while len(a_new) < 4:
    a_new = '0' + a_new
    #if len(a_new) == 4 :
    # break
    # print(a_new)
    while len(b_new) < 4:
    b_new = '0' + b_new
    #if len(b_new) == 4 :
    # break
    # print(b_new)
    print("%s:%s"%(a_new.upper(),b_new.upper()))





    我们之间的距离很近,但又很遥远
  • 相关阅读:
    操作系统
    C++流类库(11)
    C++运算符重载(10)
    C++虚函数(09)
    C++向量(08)
    C++继承(07)
    ResNet实战
    ResNet,DenseNet
    经典卷积网络VGG,GoodLeNet,Inception
    CIFAR100与VGG13实战
  • 原文地址:https://www.cnblogs.com/chen-wg/p/10766328.html
Copyright © 2020-2023  润新知