-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.cpp
93 lines (84 loc) · 3.11 KB
/
generator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int genrator(void){
// Process for getting Unix timeatamp
struct tm time;
time_t UnixTimeStamp;
time.tm_year = 2014 - 1900; // Year - 1900
time.tm_mon = 9; // Month, where 0 = jan
time.tm_mday = 31; // Day of the month
time.tm_hour = 0;
time.tm_min = 0;
time.tm_sec = 0;
time.tm_isdst = -1; // Is DST on? 1 = yes, 0 = no, -1 = unknown
UnixTimeStamp = mktime(&time);
//Process for generating unique IP Addresses
int val1 = 192;
int val2 = 168;
int val3 = 0;
int val4 = 0;
// Loop for generating 1000 IP Addresses
for (int count = 0; count < 2; count++) {
if (val4 < 255) {
val4 += 1;
} else if (val3 < 255) {
val3 += 1;
val4 = 0;
} else if (val2 < 255) {
val2 += 1;
val3 += 0;
val4 = 0;
} else if (val1 < 255) {
val1 += 1;
val2 = 0;
val3 = 0;
val4 = 0;
} else
break;
// Variabes for storing 4 partitions of IP address
char IP_Part1[10];
char IP_Part2[10];
char IP_Part3[10];
char IP_Part4[10];
// Converting IP address integer values to string
sprintf(IP_Part1, "%d", val1);
sprintf(IP_Part2, "%d", val2);
sprintf(IP_Part3, "%d", val3);
sprintf(IP_Part4, "%d", val4);
// Combining all parts of IP address
char IP_Address[100];
sprintf(IP_Address, "%s.%s.%s.%s", IP_Part1, IP_Part2, IP_Part3, IP_Part4);
// Assigning Utilization to every IP Address
int total_time =60*24; // Number of minutes for a day
int StartingTimeStamp=UnixTimeStamp;
//Creating a new file based on IP address and assigning a pointer to it
char mainPath[200]="C:\\Users\\rmste\\CLionProjects\\Temp_Project\\10-31-2014\\";
char format[15]=".txt";
char path[100];
//Creating seperate file for every IP address
sprintf(path,"%s%s%s",mainPath,IP_Address,format);
FILE *ftpr= fopen(path,"w");
for (int minute = 0; minute < total_time; minute += 1) {
StartingTimeStamp+=60;
int randomUsage1,randomUsage2;
randomUsage1=rand()%100;
randomUsage2=rand()%100;
char log1[500];
char log2[500];
char TimeStamp[10];
char cpu1Usage[10];
char cpu2Usage[10];
sprintf(TimeStamp, "%d",StartingTimeStamp);
sprintf(cpu1Usage, "%d",randomUsage1);
sprintf(cpu2Usage,"%d",randomUsage2);
sprintf(log1,"%s %s %s %s",TimeStamp,IP_Address,"0",cpu1Usage);
sprintf(log2,"%s %s %s %s",TimeStamp,IP_Address,"1",cpu2Usage);
fprintf(ftpr,"%s\n",log1);
fprintf(ftpr,"%s\n",log2);
}
fclose(ftpr);
}
return 0;
}