如何将源IP设置为http请求? [英] How to set source IP to http request?

查看:751
本文介绍了如何将源IP设置为http请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在发送http请求之前设置源IP地址(用于IP Spoofing等)。用于设置http连接的类是 HTTPURLConnection 。我发现下面的stackoverflow链接非常有用。





参见 http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request_parms1


来源添加ress字段
[仅适用于HTTPClient实现的HTTP请求]
此属性用于启用IP欺骗。它会覆盖此示例的默认本地IP地址。 JMeter主机必须具有多个IP地址(即IP别名,网络接口,设备)。该值可以是主机名,IP地址或网络接口设备,例如eth0或lo或wlan0。
如果定义了属性httpclient.localaddress,则用于所有HttpClient请求。



I need to set source IP address (for something like IP Spoofing) before sending out an http request. Class used for setting up http connection is HTTPURLConnection. I found below link on stackoverflow which is really useful.

Registering and using a custom java.net.URL protocol

As in the post, I have already created 3 classes extending URLConnection , URLStreamHandler and implementing URLStreamHandlerFactory. This looks to be working fine; however I am getting exception which I think is because I have not implemented getInputStream for URLConnection as was mentioned in above post.

I have couple of questions
1> I am extending custom URLConnection class from HTTPURLConnection, so what's the need of implementing getInputStream as anyway it's a virtual method
2> If I have to do it, can someone provide sample implementation of this method?

解决方案

JMeter already provides the IP Spoofing feature.

In Http Request Defaults, select (in version 3.0 of JMeter) advanced tab :

See http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request_parms1:

Source address field [Only for HTTP Request with HTTPClient implementation] This property is used to enable IP Spoofing. It overrides the default local IP address for this sample. The JMeter host must have multiple IP addresses (i.e. IP aliases, network interfaces, devices). The value can be a host name, IP address, or a network interface device such as "eth0" or "lo" or "wlan0". If the property httpclient.localaddress is defined, that is used for all HttpClient requests.

这篇关于如何将源IP设置为http请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆