玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python源码实例 > 脚本/批处理源码 > 正文内容

网友用python把IPv4地址变成LITNET-NAT64网段

网友用python把IPv4地址变成LITNET-NAT64网段,方便写入hosts,只对IPv6的童鞋"上外网"有用,你们懂的。不过不足两位的数值要补0,例如“6”要补为“06”,“c”要补为“0c”
 

 

1. [代码]把IPv4地址变成LITNET-NAT64网段提供转换代理的IPv6格式 

#!/usr/bin/env python

while 1:
   print "A.B.C.D"
   num1 = int(raw_input("Please input A:"))

   n1 =num1
   result1 = ''
   li1=[]
   while n1 >=16:
       if (n1%16)==10:
           li1.append("a")
       elif (n1%16)==11:
           li1.append("b")
       elif (n1%16)==12:
           li1.append("c")
       elif (n1%16)==13:
           li1.append("d")
       elif (n1%16)==14:
           li1.append("e")
       elif (n1%16)==15:
           li1.append("f")
       else:
           li1.append(n1%16)
       n1=n1/16
   if (n1)==10:
       li1.append("a")
   elif (n1)==11:
       li1.append("b")
   elif (n1)==12:
       li1.append("c")
   elif (n1)==13:
       li1.append("d")
   elif (n1)==14:
       li1.append("e")
   elif (n1)==15:
       li1.append("f")
   else:
       li1.append(n1)
   for i in range(0,len(li1)):
       result1+=str(li1[len(li1)-i-1])

   num2 = int(raw_input("Please input B:"))

   n2 =num2
   result2 = ''
   li2=[]
   while n2 >=16:
       if (n2%16)==10:
           li2.append("a")
       elif (n2%16)==11:
           li2.append("b")
       elif (n2%16)==12:
           li2.append("c")
       elif (n2%16)==13:
           li2.append("d")
       elif (n2%16)==14:
           li2.append("e")
       elif (n2%16)==15:
           li2.append("f")
       else:
           li2.append(n2%16)
       n2=n2/16
   if (n2)==10:
       li2.append("a")
   elif (n2)==11:
       li2.append("b")
   elif (n2)==12:
       li2.append("c")
   elif (n2)==13:
       li2.append("d")
   elif (n2)==14:
       li2.append("e")
   elif (n2)==15:
       li2.append("f")
   else:
       li2.append(n2)
   for j in range(0,len(li2)):
       result2+=str(li2[len(li2)-j-1])
   num3 = int(raw_input("Please input C:"))

   n3 =num3
   result3 = ''
   li3=[]
   while n3 >=16:
       if (n3%16)==10:
           li3.append("a")
       elif (n3%16)==11:
           li3.append("b")
       elif (n3%16)==12:
           li3.append("c")
       elif (n3%16)==13:
           li3.append("d")
       elif (n3%16)==14:
           li3.append("e")
       elif (n3%16)==15:
           li3.append("f")
       else:
           li3.append(n3%16)
       n3=n3/16
   if (n3)==10:
       li3.append("a")
   elif (n3)==11:
       li3.append("b")
   elif (n3)==12:
       li3.append("c")
   elif (n3)==13:
       li3.append("d")
   elif (n3)==14:
       li3.append("e")
   elif (n3)==15:
       li3.append("f")
   else:
       li3.append(n3)
   for k in range(0,len(li3)):
       result3+=str(li3[len(li3)-k-1])
   num4 = int(raw_input("Please input D:"))

   n4 =num4
   result4 = ''
   li4=[]
   while n4 >=16:
       if (n4%16)==10:
           li4.append("a")
       elif (n4%16)==11:
           li4.append("b")
       elif (n4%16)==12:
           li4.append("c")
       elif (n4%16)==13:
           li4.append("d")
       elif (n4%16)==14:
           li4.append("e")
       elif (n4%16)==15:
           li4.append("f")
       else:
           li4.append(n4%16)
       n4=n4/16
   if (n4)==10:
       li4.append("a")
   elif (n4)==11:
       li4.append("b")
   elif (n4)==12:
       li4.append("c")
   elif (n4)==13:
       li4.append("d")
   elif (n4)==14:
       li4.append("e")
   elif (n4)==15:
       li4.append("f")
   else:
       li4.append(n4)
   for h in range(0,len(li4)):
       result4+=str(li4[len(li4)-h-1])
   print "2001:778:0:ffff:64:0:"+result1+result2+":"+result3+result4

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/code/scripts-shell/ss2285.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年02月07日 - 10时54分30秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules