Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- freebsd
- Elasticsearch
- elastic stack
- XCP-ng
- application security
- 보안양파
- Kibana
- PlayBook
- Windows
- GitLab
- Kibana server is not ready yet
- Proxy
- G-suite
- ansible
- proxycfg
- xe guest utilities
- 한글가이드
- ELASTIC
- hardening
- x-pack
- docker
- macos
- ssh key 배포
- 로그인불가
- bash
- miniconda
- pfsense
- endpoint security
- centos 8
Archives
- Today
- Total
선 밖에 선 자유인
10 digit decimal <-> ip Address 파이썬 스크립트 본문
# 10digit decimal -> ip address
#convert 10digit decimal formated ipaddress to normal ipaddress #by init6 #blog.init6.me import sys def main(): #read file and convert each line to ip address. Comment out to ask for input. with open('d:\ipaddress.txt', 'r') as infile: for line in infile: print (convert(int(line))) infile.close() #ask for input (dec format) Uncomment to ask for input. #decIn = input("Enter 10 digit decimal formated ipaddress: ") def convert(decIn): if is32(decIn) == True: #convert dec to hex fullHex = hex(decIn).lstrip("0x") #Split hex number into four pairs hex1 = fullHex[0:2] hex2 = fullHex[2:4] hex3 = fullHex[4:6] hex4 = fullHex[6:8] #Convert each hex to decimal then to a string and return ip address. ipAddr = ( str(int(hex1,16)) + '.' + str(int(hex2,16)) + '.' + str(int(hex3,16)) + '.' + str(int(hex4,16)) ) return ipAddr #Checks to see if input is a 32bit int or less to make sure its a vaild ip address. def is32(n): try: bitstring=bin(n) except (TypeError, ValuueError): return False if len(bin(n)[2:]) <= 32: return True else: print ("Not a vaild 32bit 10 digit decimal") return False main()# ip address -> 10 digit decimal
#convert ip address to a 10digit decimal formated ipaddress. #by init6 #blog.init6.me import sys def main(): ipAddr = raw_input("Type in IP Address to convert to 10digit decimal: ") print ( convert(ipAddr) ) def convert(ipAddr): out = ipAddr.split('.') octets = [int(out[0]), int(out[1]), int(out[2]), int(out[3])] hexNum = '{:02X}{:02X}{:02X}{:02X}'.format(*octets) return int(hexNum, 16) main()
Comments