java 模拟多ip访问
java模拟多ip请求
package url_demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.Random;
public class HttpUtilTest {
private int index = 0;
public String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
URLConnection conn = realUrl.openConnection();
// 随机生成ip
String ip = randIP();
conn.setRequestProperty("X-Forwarded-For", ip);
conn.setRequestProperty("HTTP_X_FORWARDED_FOR", ip);
conn.setRequestProperty("HTTP_CLIENT_IP", ip);
conn.setRequestProperty("REMOTE_ADDR", ip);
conn.setRequestProperty("Host", "");
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Content-Length", "17");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Origin", "ORIGIN");
conn.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Referer", "REFERER");
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
conn.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6,ja;q=0.4,pt;q=0.2");
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
out.print(param);
out.flush();
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
synchronized (this) {
DemoUtl.index = DemoUtl.index + 1;
}
System.out.println("第" + DemoUtl.index + "次访问; --> || 当前线程:" + param + " || 请求成功! || 模拟ip: " + ip
+ " || 返回结果: " + result.toString().hashCode());
} catch (Exception e) {
// System.out.println("发送 POST 请求出现异常!" + e);
// e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
public static String randIP() {
Random random = new Random(System.currentTimeMillis());
return (random.nextInt(255) + 1) + "." + (random.nextInt(255) + 1) + "." + (random.nextInt(255) + 1) + "."
+ (random.nextInt(255) + 1);
}
}
package url_demo;
import java.util.Random;
public class DemoUtl {
public static int index = 0;
public static void main(String[] args) throws InterruptedException {
try {
for (int i = 0; i < 100000; i++) {
Thread.sleep((new Random()).nextInt(200) + 100);
new Thread(new Runnable() {
@Override
public void run() {
for (int j = 0; j < 100000; j++) {
try {
Thread.sleep((new Random()).nextInt(3200) + 1500);
HttpUtilTest tt = new HttpUtilTest();
tt.sendPost(
"https://www.baidu.com",
Thread.currentThread().getName());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws InterruptedException {
ExpiryMap<String, Object> map = ExpiryMap.getInstance();
// 往map写入1-1000, key和value相同
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int i = 1; i <= 10; i++) {
map.put(i + "", i, i * 200);
}
}
};
int threadNum = 2;// 线程数
// List<Thread> threadList = new ArrayList<>();
for (int i = 0; i < threadNum; i++) {
Thread thread = new Thread(runnable);
// threadList.add(thread);
thread.start();
}
// // 主线程等待子线程执行完成
// for (Thread thread : threadList) {
// try {
// thread.join();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// System.out.println(map.size());// 结果可能大于1000
}
java 模拟多ip访问的更多相关文章
- java模拟网页http-url访问
package com.iflytek; import java.io.InputStream; import java.net.HttpURLConnection; import java.net. ...
- java模拟http请求(代理ip)
java实现动态切换上网IP (ADSL拨号上网) java动态设置IP java模拟http的Get/Post请求 自动生成IP模拟POST访问后端程序 JAVA 动态替换代理IP并模拟POST
- java爬虫进阶 —— ip池使用,iframe嵌套,异步访问破解
写之前稍微说一下我对爬与反爬关系的理解 一.什么是爬虫 爬虫英文是splider,也就是蜘蛛的意思,web网络爬虫系统的功能是下载网页数据,进行所需数据的采集.主体也就是根据开始的超链接,下 ...
- Jsoup实现java模拟登陆
Jsoup实现java模拟登陆 2013-10-29 14:52:05| 分类: web开发|举报|字号 订阅 下载LOFTER我的照片书 | 1:如何获取cookies. 1.1 ...
- Java模拟登陆02【转载】
在使用java访问URL时,如果该URL需要身份验证,那么就不能够直接访问,因为没有登陆.那么,如何解决这个问题呢? 方法是使用java模拟登陆,登陆后记录下cookie信息,在下次发起请求时 ...
- java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱
//如果网页源码中有些内容是js渲染过来的,那你通过HttpClient直接取肯定取不到,但是这些数据一般都是通过异步请求传过来的(一般都是通过ajax的get或者post方式).那么你可以通过火狐浏 ...
- Tomcat配置域名/IP访问及其中遇到的问题注意事项
1.先在tomcat下的conf下找到server.xml文件,用记事本打开后,首先对端口号进行修改,以前一直以为8080是默认的端口号,其实默认的端口号是80 <Connector port= ...
- tomcat相关配置技巧梳理 (修改站点目录、多项目部署、限制ip访问、大文件上传超时等)
tomcat常用架构:1)nginx+tomcat:即前端放一台nginx,然后通过nginx反向代理到tomcat端口(可参考:分享一例测试环境下nginx+tomcat的视频业务部署记录)2)to ...
- 浏览器与服务器交互原理以及用java模拟浏览器操作v
浏览器应用服务器JavaPHPApache * 1,在HTTP的WEB应用中, 应用客户端和服务器之间的状态是通过Session来维持的, 而Session的本质就是Cookie, * 简单的讲,当浏 ...
随机推荐
- Python中如何使用线程池和进程池?
进程池的使用 为什么要有进程池?进程池的概念. 在程序实际处理问题过程中,忙时会有成千上万的任务需要被执行,闲时可能只有零星任务. 那么在成千上万个任务需要被执行的时候,我们就需要去创建成千上万个进程 ...
- LeetCode 983. Minimum Cost For Tickets
原题链接在这里:https://leetcode.com/problems/minimum-cost-for-tickets/ 题目: In a country popular for train t ...
- 用TortoiseSVN从github下载单个文件
问题描述: github是一个很好的共享代码管理仓库,我们可以从github上直接以压缩包的形式直接download整个项目,也可以通过git,用git clone + URL 命令下载整个目录. 但 ...
- Collecting metrics with the PostgreSQL and TimescaleDB output plugin for Telegraf
转自:https://docs.timescale.com/v1.3/tutorials/telegraf-output-plugin 文章演示了如何使用pg output 插件 以及Telegraf ...
- redis windows版本的使用
ServiceStack的redis-windows下载 下载新的版本解压到硬盘,使用黑窗口切换到路径后执行 redis-server redis.windows.conf 即可看到redis启动到6 ...
- CH定理与线性递推
才发觉自己数学差的要死,而且脑子有点浑浑噩噩的,学了一个晚上才学会 如果说的有什么不对的可以在下面嘲讽曲明 以下无特殊说明时,默认方阵定义在实数域上,用\(|A|\)表示\(A\)的行列式 特征值与特 ...
- Android Studio3.0的下载及其安装详解加eclipse下载安装配置jdk9
关注我,每天都有优质技术文章推送,工作,学习累了的时候放松一下自己. 本篇文章同步微信公众号 欢迎大家关注我的微信公众号:「醉翁猫咪」 今天我们来讲解如何下载android studio 3.0及其 ...
- 【转】Resource Localization in YARN
一个Applciation运行在YARN上的流程为,从YARN Client向ResourceManager提交任务,将Applciation所需资源提交到HDFS中,然后ResourceManage ...
- mysql 唯一键
唯一键特点: 1.唯一键在一张表中可以有多个. 2.唯一键允许字段数据为NULL,NULL可以有多个(NULL不参与比较) //一个表中允许存在多个唯一键,唯一键允许为空,在不为空的情况下,不允许重复 ...
- 无法定位程序输入点到xxx.dll
Q:安装pytorch时报错无法定位程序输入点到Anaconda3\Library\bin\libssl-1_1-x64.dll A:下载libssl-1_1-x64.dll覆盖bin下的文件 下载地 ...