In [12]:
import hmac
import hashlib
import Crypto.Cipher.AES
import socket
import struct
from array import array
import ipaddress
import numpy as np
key = "secret"
text = "192.168.0."
signature = hmac.new(key,text,hashlib.sha256).hexdigest()
print signature
text = "192.168.0."
signature = hmac.new(key,text,hashlib.sha256).hexdigest()
print signature
key = "secret2"
text = "192.168.0."
signature = hmac.new(key,text,hashlib.sha256).hexdigest()
print signature
In [34]:
ip=ipaddress.ip_address(u"255.255.255.255")
In [35]:
ip
Out[35]:
In [36]:
addr = int(ip)
In [37]:
addr
Out[37]:
In [38]:
print "addr:\n",format(addr,'032b')
In [39]:
net = addr >> 8 << 8
print "addr:\n",format(net,'032b')
In [40]:
ipaddress.IPv4Address(net)
Out[40]:
In [66]:
host = addr & (2**8-1)
print "addr:\n",format(host,'032b')
In [67]:
ipaddress.IPv4Address(host)
Out[67]:
In [68]:
Out[68]:
In [72]:
2**8
Out[72]:
In [73]:
ip=ipaddress.ip_address(u"192.168.0.1")
In [74]:
addr = int(ip)
In [101]:
key = "secret"
ip=ipaddress.ip_address(u"192.168.0.0")
print ip.exploded
signature = hmac.new(key,ip.exploded,hashlib.sha256).hexdigest()
print signature
In [104]:
key = "secret"
ip=ipaddress.ip_address(u"192.168.1.0")
print ip.exploded
signature = hmac.new(key,ip.exploded,hashlib.sha256).hexdigest()
print signature
In [ ]:
In [99]:
Out[99]:
In [102]:
ip=ipaddress.ip_address(u"2001:db8::0")
print ip.exploded
signature = hmac.new(key,ip.exploded,hashlib.sha256).hexdigest()
print signature
In [ ]:
In [106]:
ip=ipaddress.ip_address(u"2001:DB8:0:0:8:800:200C:0")
print ip.exploded
signature = hmac.new(key,ip.exploded,hashlib.sha256).hexdigest()
print signature
In [107]:
ip=ipaddress.ip_address(u"2001:DB8:0:0:8:800:200C:0")
print ip.exploded
signature = hmac.new(key,ip.exploded,hashlib.sha256).hexdigest()
print signature
In [ ]: