|
#!/usr/bin/env python |
|
# -*- coding: utf-8 -*- |
|
''' |
|
Refer to: |
|
http://support.f5.com/kb/en-us/solutions/public/6000/900/sol6917.html |
|
''' |
|
|
|
import urllib2 |
|
import os |
|
|
|
|
|
URL = None |
|
|
|
def get_cookie(): |
|
''' |
|
Get cookie info |
|
''' |
|
pass |
|
|
|
def encode_ip(): |
|
''' |
|
Encode IP address into wpa2 format |
|
''' |
|
# Convert each octet value to equivalent 1-byte hex value |
|
ip_address = '10.0.1.254' |
|
split_ip = ip_address.split('.') |
|
# Reverse the order of the hex bytes and concatenate |
|
# to make one 4-byte hex value |
|
hexed_ip = [] |
|
for ip in split_ip[::-1]: |
|
hexed_ip.append(hex(int(ip))) |
|
first_hex_num = hexed_ip.pop(0) |
|
hexed_ip = ''.join(hexed_ip).replace('x','') |
|
concat_hex_num = "%s%s" % (first_hex_num, hexed_ip) |
|
# Convert the resulting 4-byte hexadecimal value to its |
|
# decimal equivalent |
|
return int(concat_hex_num, 16) |
|
|
|
def encode_port(): |
|
''' |
|
Encodes port number |
|
''' |
|
# Convert decimal port value to hex value and |
|
# Reverse the order of the 2 hex bytes |
|
port = 23205 |
|
hex_port = list(hex(port)) |
|
hex_port.insert(2, hex_port.pop(-2)) |
|
hex_port.insert(3, hex_port.pop(-1)) |
|
# Convert the resulting 2-byte hex value to |
|
# decimal |
|
return int(''.join(hex_port), 16) |
|
|
|
def decode_ip(): |
|
pass |
|
|
|
def decode_port(): |
|
''' |
|
Decoded port |
|
''' |
|
pass |
|
|
|
def display_cookie(): |
|
''' |
|
Displays cookie |
|
''' |
|
# if option is encode then do this: |
|
encoded_ip = str(encode_ip()) |
|
encoded_port = str(encode_port()) |
|
padder = '0000' |
|
print "%s.%s.%s" % (encoded_ip, encoded_port, padder) |
|
# elif option is decode then do this: |
|
# decode code goes here |
|
|
|
def main(): |
|
''' |
|
Main program |
|
''' |
|
print "Encoded cookie: " |
|
display_cookie() |
|
|
|
if __name__ == "__main__": |
|
main() |