package com.ccj.wfy.makedata;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
public class MocklLog {
//[09/02/2020:14:31:50 +0800] 210.35.184.9 - 594 - POST https://www.bilibili.com/video/av52167219 404 26 - MISS
private static String[] urls = {"http://www.ruozedata.com",
"https://ruoze.ke.qq.com",
"https://www.bilibili.com/video/av76542615",
"https://www.bilibili.com/video/av80522857",
"https://www.bilibili.com/video/av73376233",
"https://www.bilibili.com/video/av52167219",
"https://www.bilibili.com/video/av30031910",
"https://www.bilibili.com/video/av34829124"
};
private static String[] method={"GET","POST"};
public static String getRandomIp() {
// ip范围
int[][] range = { { 607649792, 608174079 }, // 36.56.0.0-36.63.255.255
{ 1038614528, 1039007743 }, // 61.232.0.0-61.237.255.255
{ 1783627776, 1784676351 }, // 106.80.0.0-106.95.255.255
{ 2035023872, 2035154943 }, // 121.76.0.0-121.77.255.255
{ 2078801920, 2079064063 }, // 123.232.0.0-123.235.255.255
{ -1950089216, -1948778497 }, // 139.196.0.0-139.215.255.255
{ -1425539072, -1425014785 }, // 171.8.0.0-171.15.255.255
{ -1236271104, -1235419137 }, // 182.80.0.0-182.92.255.255
{ -770113536, -768606209 }, // 210.25.0.0-210.47.255.255
{ -569376768, -564133889 }, // 222.16.0.0-222.95.255.255
};
Random rdint = new Random();
int index = rdint.nextInt(10);
String ip = num2ip(range[index][0] + new Random().nextInt(range[index][1] - range[index][0]));
return ip;
}
/*
* 将十进制转换成IP地址
*/
public static String num2ip(int ip) {
int[] b = new int[4];
String x = "";
b[0] = (int) ((ip >> 24) & 0xff);
b[1] = (int) ((ip >> 16) & 0xff);
b[2] = (int) ((ip >> 8) & 0xff);
b[3] = (int) (ip & 0xff);
x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]);
return x;
}
// 随机生成时间的范围
public static Date getTimer(){
Random R = new Random();
Calendar now = Calendar.getInstance();
// System.out.println(R.nextBoolean());
//System.out.println(Calendar.YEAR);
now.add(Calendar.YEAR, R.nextBoolean() ? 0:-R.nextInt(3));
now.add(Calendar.MONTH, R.nextBoolean() ? 0:-R.nextInt(2));
now.add(Calendar.DATE, R.nextBoolean() ? 0:-R.nextInt(30));
now.add(Calendar.HOUR, R.nextBoolean() ? 0:-R.nextInt(8));
now.add(Calendar.MINUTE, R.nextBoolean() ? 0:-R.nextInt(50));
now.add(Calendar.SECOND, R.nextBoolean() ? R.nextInt(5):-R.nextInt(50));
return now.getTime();
}
public static String[] httpcode={"200","404","500","202","506"};
public static String[] cacheStatus={"MISS","HIT"};
public static void main(String[] args) throws Exception {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("data/access.txt"))));
String[] a={"pxj","wfy","ccj","zmj","xwc","lzh","zcl","wlp","wxc","pk","jpeson"};
//[09/02/2020:14:31:50 +0800] 222.26.76.40 - 271 - GET https://www.bilibili.com/video/av80522857 200 18 737 HIT
TimeZone timeZone = TimeZone.getTimeZone("GMT+8:00");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("[dd/MM/yyyy:HH:mm:ss ZZZ]");
for (int i=0;i<50;i++){
Random random = new Random();
writer.write(simpleDateFormat.format(getTimer()));
writer.write("\t");
writer.write(getRandomIp());
writer.write("\t");
writer.write("-");
writer.write("\t");
writer.write(String.valueOf(random.nextInt(3000)));
// writer.write(300);
writer.write("\t");
writer.write("-");
writer.write("\t");
writer.write(urls[random.nextInt(urls.length)]);
writer.write("\t");
writer.write(httpcode[random.nextInt(httpcode.length)]);
writer.write("\t");
writer.write(String.valueOf(random.nextInt(300)));
// writer.write(120);
writer.write("\t");
writer.write(random.nextBoolean()?String.valueOf(random.nextInt(5000)+1):"-");
// writer.write(600);
writer.write("\t");
writer.write(cacheStatus[random.nextInt(cacheStatus.length)]);
writer.newLine();
}
writer.flush();
writer.close();
}
}
[21/01/2020:00:57:35 +0800] 182.85.29.95 - 2142 - https://www.bilibili.com/video/av52167219 202 132 950 MISS
[22/01/2020:00:57:42 +0800] 121.76.187.67 - 724 - https://ruoze.ke.qq.com 404 248 - MISS
[11/01/2020:00:57:46 +0800] 123.232.202.86 - 1300 - https://www.bilibili.com/video/av73376233 202 124 4075 MISS
[03/02/2020:23:57:44 +0800] 222.42.54.200 - 242 - https://www.bilibili.com/video/av73376233 506 50 - MISS
[11/02/2020:00:21:11 +0800] 61.235.199.21 - 344 - https://www.bilibili.com/video/av76542615 506 217 - MISS
[09/02/2020:00:57:06 +0800] 210.33.102.240 - 407 - https://www.bilibili.com/video/av80522857 404 137 - MISS
[27/01/2020:18:57:43 +0800] 106.84.225.211 - 2808 - https://www.bilibili.com/video/av34829124 404 131 - HIT
[18/01/2020:18:57:36 +0800] 171.15.58.181 - 1198 - https://ruoze.ke.qq.com 404 184 3626 HIT
[11/02/2018:00:57:36 +0800] 121.76.245.6 - 646 - https://www.bilibili.com/video/av76542615 404 61 - HIT
[03/02/2020:21:53:04 +0800] 182.84.59.190 - 2107 - https://www.bilibili.com/video/av34829124 200 240 - MISS
[10/02/2020:17:46:22 +0800] 61.236.164.220 - 1872 - https://www.bilibili.com/video/av30031910 500 41 297 MISS
[11/02/2018:00:43:56 +0800] 210.41.4.195 - 2219 - https://www.bilibili.com/video/av76542615 500 3 2556 HIT
[10/01/2020:22:57:17 +0800] 61.235.75.52 - 2716 - https://www.bilibili.com/video/av73376233 404 59 - MISS
[14/01/2020:22:57:46 +0800] 123.233.0.213 - 528 - https://www.bilibili.com/video/av30031910 200 66 - MISS
[11/01/2018:00:57:46 +0800] 210.36.160.166 - 964 - https://www.bilibili.com/video/av76542615 200 168 2462 HIT
[11/01/2019:00:26:46 +0800] 210.43.15.8 - 143 - https://www.bilibili.com/video/av52167219 202 149 - HIT
[15/12/2017:17:18:09 +0800] 36.61.236.152 - 2069 - https://www.bilibili.com/video/av76542615 200 80 - MISS
[27/12/2019:22:49:42 +0800] 123.233.189.145 - 1248 - https://www.bilibili.com/video/av80522857 500 142 - HIT
[15/01/2020:00:57:45 +0800] 36.56.17.189 - 1617 - http://www.ruozedata.com 202 160 61 HIT
[11/02/2020:00:57:43 +0800] 36.60.65.20 - 1683 - https://www.bilibili.com/video/av73376233 500 72 - MISS
[10/02/2018:20:25:42 +0800] 222.53.237.240 - 2285 - https://www.bilibili.com/video/av52167219 200 294 3962 MISS
[11/02/2020:00:45:45 +0800] 210.32.44.10 - 111 - https://www.bilibili.com/video/av76542615 506 261 - HIT
[16/01/2018:21:57:43 +0800] 171.14.245.204 - 1782 - http://www.ruozedata.com 200 91 - MISS
[15/01/2020:20:56:54 +0800] 106.92.18.128 - 2790 - https://www.bilibili.com/video/av80522857 500 241 - HIT
[07/02/2020:22:57:46 +0800] 182.82.43.51 - 1657 - https://www.bilibili.com/video/av80522857 500 235 2684 MISS
[11/02/2019:00:56:55 +0800] 182.81.46.14 - 850 - http://www.ruozedata.com 200 1 4630 HIT
[11/02/2018:00:57:43 +0800] 210.35.81.176 - 1920 - http://www.ruozedata.com 506 179 2766 HIT
[05/02/2020:00:45:44 +0800] 36.56.122.130 - 1504 - http://www.ruozedata.com 202 245 - MISS
[10/02/2020:23:27:12 +0800] 171.15.230.31 - 744 - https://www.bilibili.com/video/av80522857 202 93 2843 HIT
[28/01/2020:18:57:45 +0800] 171.10.237.41 - 2953 - https://www.bilibili.com/video/av30031910 404 204 - HIT
[11/02/2020:00:29:42 +0800] 106.84.182.158 - 1240 - https://www.bilibili.com/video/av34829124 506 296 - MISS
[01/02/2020:22:57:43 +0800] 210.39.179.34 - 1613 - https://www.bilibili.com/video/av80522857 506 299 - HIT
[11/02/2018:00:49:45 +0800] 36.60.175.73 - 167 - https://ruoze.ke.qq.com 506 43 - MISS
[11/01/2020:00:25:03 +0800] 222.60.219.44 - 1066 - https://www.bilibili.com/video/av34829124 200 214 - MISS
[11/02/2018:00:16:07 +0800] 222.68.136.126 - 2965 - https://ruoze.ke.qq.com 404 188 468 MISS
[10/02/2019:22:18:44 +0800] 182.81.182.109 - 599 - https://www.bilibili.com/video/av30031910 202 152 - MISS
[27/01/2020:00:57:45 +0800] 106.92.37.98 - 2493 - https://www.bilibili.com/video/av30031910 202 134 2806 MISS
[11/02/2020:00:42:32 +0800] 36.62.17.101 - 895 - http://www.ruozedata.com 404 46 515 HIT
[14/01/2020:23:09:53 +0800] 222.84.71.88 - 1106 - http://www.ruozedata.com 500 46 523 MISS
[11/02/2018:00:57:43 +0800] 36.63.214.130 - 1041 - https://ruoze.ke.qq.com 202 108 - HIT
[11/02/2020:00:57:11 +0800] 182.87.166.22 - 872 - https://ruoze.ke.qq.com 404 185 - HIT
[24/01/2020:21:31:05 +0800] 123.233.20.33 - 2946 - https://www.bilibili.com/video/av34829124 500 141 - HIT
[11/02/2020:00:47:31 +0800] 121.77.77.2 - 2107 - https://www.bilibili.com/video/av76542615 404 63 - MISS
[01/01/2020:00:57:16 +0800] 171.9.210.191 - 1889 - https://www.bilibili.com/video/av73376233 500 193 1030 HIT
[11/01/2019:00:57:42 +0800] 182.85.28.105 - 1723 - https://www.bilibili.com/video/av80522857 506 116 3309 HIT
[10/02/2020:21:57:10 +0800] 106.85.197.14 - 2382 - https://ruoze.ke.qq.com 202 257 - HIT
[11/02/2020:00:57:21 +0800] 222.43.89.88 - 2439 - https://ruoze.ke.qq.com 404 37 - MISS
[10/02/2020:20:55:42 +0800] 139.214.107.179 - 1078 - https://www.bilibili.com/video/av76542615 506 17 - HIT
[10/01/2020:17:57:45 +0800] 121.76.158.27 - 606 - https://www.bilibili.com/video/av76542615 202 71 4224 HIT
[11/02/2020:00:34:25 +0800] 36.60.26.49 - 348 - https://www.bilibili.com/video/av76542615 500 162 4809 HIT
作者:pxj(潘陈)
日期:2020-02-11 凌晨0:54:20