mirror of
https://github.com/Febbweiss/log-generator.git
synced 2026-03-04 22:25:40 +00:00
Add User Agents
This commit is contained in:
@@ -14,12 +14,19 @@ public class Utils {
|
||||
private static final String LOG_SEPARATOR = ",";
|
||||
private static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||
private static final List<String> ips = new ArrayList<String>();
|
||||
private static final List<String> products = new ArrayList<String>();
|
||||
private static final List<String> userAgents = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
readFromFile("ips.txt", ips);
|
||||
readFromFile("useragents.txt", userAgents);
|
||||
}
|
||||
|
||||
private static void readFromFile(String file, List<String> list) {
|
||||
|
||||
try {
|
||||
InputStream is = Utils.class.getClassLoader().getResourceAsStream(file);
|
||||
Scanner scan = new Scanner(is);
|
||||
scan.useDelimiter("\n");
|
||||
while (scan.hasNext()) {
|
||||
String line = scan.next().trim();
|
||||
if (line.length() > 0)
|
||||
@@ -28,6 +35,7 @@ public class Utils {
|
||||
} catch (Exception e) {
|
||||
log.error("Error during read/parse of file: ", file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String fmtE(Enum e) {
|
||||
@@ -48,6 +56,10 @@ public class Utils {
|
||||
return getRandomFromList(ips);
|
||||
}
|
||||
|
||||
private static String getRandomUA() {
|
||||
return getRandomFromList(userAgents);
|
||||
}
|
||||
|
||||
private static double getRandomPrice() {
|
||||
int min = 30;
|
||||
int max = 99;
|
||||
@@ -71,6 +83,9 @@ public class Utils {
|
||||
.append("id=")
|
||||
.append(id)
|
||||
.append(LOG_SEPARATOR)
|
||||
.append("ua=")
|
||||
.append(getRandomUA())
|
||||
.append(LOG_SEPARATOR)
|
||||
.append("ip=")
|
||||
.append(getRandomIP())
|
||||
.append(LOG_SEPARATOR)
|
||||
@@ -87,6 +102,9 @@ public class Utils {
|
||||
.append("id=")
|
||||
.append(id)
|
||||
.append(LOG_SEPARATOR)
|
||||
.append("ua=")
|
||||
.append(getRandomUA())
|
||||
.append(LOG_SEPARATOR)
|
||||
.append("ip=")
|
||||
.append(getRandomIP())
|
||||
.append(LOG_SEPARATOR);
|
||||
@@ -126,8 +144,4 @@ public class Utils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static {
|
||||
readFromFile("ips.txt", ips);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10919
src/main/resources/useragents.txt
Normal file
10919
src/main/resources/useragents.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user