Created
August 24, 2012 18:48
-
-
Save ottomata/3454197 to your computer and use it in GitHub Desktop.
Prefix Preserving?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./anon_ip 192.168.1.31 | |
192.168.1.31 -> 255.39.206.200 | |
# ./anon_ip 192.168.1.32 | |
192.168.1.32 -> 255.39.206.225 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <getopt.h> | |
#include <string.h> | |
#include <arpa/inet.h> | |
#include "anonymization.h" | |
#include "anon_prefix_preserving.h" | |
int main(int argc, char *argv[]) | |
{ | |
char ip[4]; | |
inet_pton(AF_INET, argv[1], (void *)ip); | |
// unsigned int ip = (unsigned int)atoi(argv[0]); | |
// unsigned char raw_ip[4]; | |
// memcpy(raw_ip, &ip, 4); | |
unsigned char anon_ip[4]; | |
memcpy(anon_ip, ip, 4); | |
prefix_preserving_anonymize_field(anon_ip); | |
printf("%s -> %i.%i.%i.%i\n", argv[1], anon_ip[0], anon_ip[1], anon_ip[2], anon_ip[3]); | |
// printf("ip: %i.%i.%i.%i\n", raw_ip[3], raw_ip[2], raw_ip[1], raw_ip[0]); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./anon_ip 192.168.1.31 | |
192.168.1.31 -> 97.1.208.192 | |
# ./anon_ip 192.168.1.32 | |
192.168.1.32 -> 68.1.196.254 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include "panonymizer.h" | |
#include <arpa/inet.h> | |
int main(int argc, char * argv[]) { | |
// Provide your own 256-bit key here | |
unsigned char my_key[32] = | |
{21,34,23,141,51,164,207,128,19,10,91,22,73,144,125,16, | |
216,152,143,131,121,121,101,39,98,87,76,45,42,132,34,2}; | |
unsigned int raw_addr, anonymized_addr; | |
// Create an instance of PAnonymizer with the key | |
PAnonymizer my_anonymizer(my_key); | |
// float packet_time; | |
unsigned int packet_size, packet_addr1, packet_addr2, packet_addr3, packet_addr4; | |
if (argc != 2) { | |
fprintf(stderr, "usage: ip_address\n"); | |
exit(-1); | |
} | |
inet_pton(AF_INET, argv[1], (void *)&raw_addr); | |
//Anonymize the raw IP | |
anonymized_addr = my_anonymizer.anonymize(raw_addr); | |
//convert the anonymized IP from unsigned int format to a.b.c.d format | |
packet_addr1 = anonymized_addr >> 24; | |
packet_addr2 = (anonymized_addr << 8) >> 24; | |
packet_addr3 = (anonymized_addr << 16) >> 24; | |
packet_addr4 = (anonymized_addr << 24) >> 24; | |
printf("%s -> %u.%u.%u.%u\n", argv[1], packet_addr1, packet_addr2, packet_addr3, packet_addr4 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment