allan

Checkpoint Log IP-Hex Converter

Sep 28th, 2022 (edited)
1,093
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | Source Code | 0 0
  1. # for pasting into a firewall's Python3 IDLE - no error checking.
  2. # make sure to use the raw version of this paste!
  3.  
  4. def ip_hex():
  5.  txt = input('IP: ')
  6.  while txt != '':
  7.   ip_int = [ int(oct) for oct in txt.split('.') ]
  8.   ip_hex = list(map(lambda n:'%02x' % n, ip_int))
  9.   out_str = ''.join(ip_hex)
  10.   if out_str[0] == '0':
  11.    out_str = out_str[1:]
  12.   print(out_str)
  13.   txt = input('IP: ')
  14.  
  15. def hex_ip():
  16.  txt = input('hex: ')
  17.  while txt != '':
  18.   if txt[0:2] == '0x':
  19.    txt = txt[2:]
  20.   if (len(txt) % 2) == 1:
  21.    txt = '0' + txt
  22.   oct = list()
  23.   for pos in range(0, len(txt), 2):
  24.    oct.append(str(int(txt[pos:pos + 2], 16)))
  25.   print('.'.join(oct))
  26.   txt = input('hex: ')
  27.  
  28.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment