将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()))
将IP转换为16进制,用于IPv4-IPv6的更多相关文章
- java中把字节数组转换为16进制字符串
把字符串数组转换为16进制字符串 import java.security.MessageDigest; public class StringUtil { public StringUtil() { ...
- MFC 编辑框输入16进制字符串转换为16进制数或者10进制数据计算
1.编辑框添加变量,并选择变量类型为CString. 2. 使用“_tcstoul”函数将Cstring 类型转换为16进制/10进制数进行计算.
- asp.net AES加密跟PHP的一致,将加密的2进制byte[]转换为16进制byte[] 的字符串获得
<?php class AESUtil { public static function encrypt($input, $key) { $size = mcrypt_get_block_siz ...
- js中如何把RGB颜色转换为16进制颜色
将RGB颜色值转换为16进制颜色值,主要是将 R.G.B 值分别转换为对应的十六进制值,填入 #RRGGBB 中. 推荐在线颜色转换工具:http://www.ecjson.com/rgbhex/ 例 ...
- js中十进制数转换为16进制
使用 Number类的 toString()方法: var num = 255; console.log(num.toString(16));//输出FF
- c# 读取二进制文件并转换为 16 进制显示
string result = ""; string filePath = "xxx.bin"; if (File.Exists(filePath)) { by ...
- hex(x) 将整数x转换为16进制字符串
>>> a = 122 >>> b = 344 >>> c = hex(a) >>> d = hex(b) >>&g ...
- 普通rgb转换为16进制
http://www.zhangxinxu.com/study/201003/color-exchange-test.html
- js 二进制转换为16进制数
<!DOCTYPE html> <html> <head> <title>远程监控</title> </head> <bo ...
随机推荐
- vue 单独页面body css 样式设置
给某个page下template中的第一个div设置如下样式: .body-bg { position: absolute; width: 100%; height: 100%; top:; left ...
- LeetCode 141. Linked List Cycle 判断链表是否有环 C++/Java
Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked lis ...
- 文件服务之二:ftp协议
FTP连接 命令连接 传输命令(客户端发给服务端的命令),服务端的21/tcp 数据连接 传输数据(传输数据时建立,数据传输完拆除) 数据链接的建立方法:主动.被动 主动模式(PORTstyle服务器 ...
- [PHP+JS]微信卡券(潦草笔记,全代码,亲测通过)
群发卡券可以通过客服消息推送 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140547 后端代码: define('A ...
- [HTML]将错误alert出来[转]
<script type="text/javascript"> /** * @param {String} errorMessage 错误信息 * @param {St ...
- MTK6261之Catcher工具的Database Path
在Catcher使用使用的时候我们常用要选择Database Path 设置数据库的路径,编译自动生成的文件: 设置路径选项: (一般是在对应工程文件的路径 \tst\database_classb) ...
- list之flex布局写法
list之flex布局写法 移动端实际场景中经常会遇到将header置顶,然后下面list需要滚动的情况,通常的做法会是将header使用fixed的方式固定到顶部,然后list主体相对于header ...
- cuda 配置要点
1. 安装驱动 :sudo apt-get install nvidia- 2. 安装cuda : cuda 文件中包含驱动程序,因此在安装过程中当被问及是否安装驱动时,选择no 3. 安装cudnn ...
- event 事件2
4.事件类型 “DOM3级事件”规定了一下几类事件: 1)UI事件(用户界面事件),当用户与页面元素交互时触发 2)焦点事件,当元素获得或失去焦点时触发 3)鼠标事件,当用户通过鼠标在页面上执行操作时 ...
- Sprite/MovieClip的Enter_Frame事件,不受addChild/removeChild影响
简单点讲:Sprite或MovieClip对象一旦为其添加了Enter_Frame事件监听,对应的Enter_Frame处理函数将会马上被调用,并一直执行下去(不管你是否将其addChild到显示列表 ...