Reputation: 29
i need to generate unique values by using ipv4 and ipv6 addresses i.e if i input 192.37.4.60; a unique key should be generated and when i enter 192.60.4.37 a another key should be generated. How can i do this can any one help me out and i can also input ipv6 address also how to generate unique values to each input. can any one propse any algorithm or any present algorithm
Upvotes: 2
Views: 1298
Reputation: 14346
You don't state any required properties of the keys excet that thy should be unique, so the obvious solution is to use the canonicalized IP addresses as keys. You can turn the addresses into numbers the obvious way, but be warned that IPv6 addresses make for huge numbers, so you'll need the BigInt implementation in whatever language you use.
(If you didn't actually mean that all 340 undecillion addresses should have unique keys, then of course you should look at normal hash functions instead.)
Upvotes: 0
Reputation: 2699
There are a couple of solution possible depending of what are the needs of your problem.
You might want to look to use multiple source for your algorithm. Consider using, in combination with the MAC address, any other material-related information that you can obtain from the machine/client on which the application will run
Upvotes: 0
Reputation: 2362
one possible solution can be to use left shift operator and add. For example if a, b, c and d represent the octets then following code will give you a unique value
int a=1;
int b=2;
int c=3;
int d=4;
int value =(a<<24)+(b<<16)+(c<<8)+d;
Upvotes: 0
Reputation: 48785
Convert the IP into its numerical (decimal) representation:
10.0.0.1 -> 00001010 00000000 00000000 00000001 -> 167772161
This is how a lot of IP addresses are stored internally. It's nice because it only requires 32 bits of storage. You can do this for IPv6 too, but it's going to require something bigger than a uint32.
Upvotes: 2
Reputation: 22659
The IPs are pretty unique :) Especially IPv6 addresses. Also, you can always use a hash algorithm (e.g. MD5, SHA1 etc.) to create a "key". It will be unique, as long as the input data is also unique :)
Upvotes: 1
Reputation: 56282
Output the input IP address: voilà, requirements met!
(If my solution doesn't work for you, it means you need to add more details to your question)
Upvotes: 0