我们需要做一次测试,由A向B发送HTTP请求,要求这些请求的IP地址是不同的,A会检查HTTP响应以判断是否正确。 问题是逐步明确的。
最初的测试只是要求一个IP发送,很简单,我写了一个Python的脚本,使用urllib库完成了所有的事情。能够值得 一提的是,urllib自己处理了302的跳转,这个出乎我的预料,这个还需要读文档。
但是一到多个IP地址的时候,问题就不那么容易了。
我首先向的当然是直接在原来的脚本上修改,篡改发送的IP地址;所以先Google有没有人做个这个事情。所以就在 stackoverflow上找到了这个。这里就不贴出这段代码了,因为它是不能工作的,我运行过;具体原因先按下不表(或者说我还需要更清楚些)。这里面提到的东西需要再研究,对于理解Python的urllib库将会很有帮助。
然后我发现了这个,让我觉得非常尴尬,这么基础的问题我竟然没有考虑到。
简单点说就是:开始发送HTTP协议的数据之前必须有一个TCP链接已经建立了;如果修改了握手的第一个数据包,第二个数据包根本回不了A主机,TCP根本建立不起来;更不要说HTTP协议了。
有人给出了这个脚本链接,有待研究。
人生的终极命题还是在无法承受之下如何前行。所以,办法必须要有:
- Linux的IP alias特性,可以给一台机器配置多个IP地址,使用用这些IP地址发送数据。
- 利用libpcap分析包,用libnet发送包。
- host address: A unique address assigned to a communications device in a computer. If a computer has multiple communications devices (e.g., Ethernet cards or modems), each of these devices will have its own unique address.
- This means that a host (computer or router) can be multi-homed, i.e., have multiple IP addresses. This can also be artificially created by assigning different IP addresses to the same device (called IP aliasing).
- Primary address
- Secondary address
- ip addr add 192.168.4.62/24 dev wlo1
- 使用1中脚本使用的方法
- ip addr del 192.168.4.62/24 dev wlo1
#### /sbin/sysctl net.ipv4.conf.eth0.promote_secondaries=1
If this is enabled, and primary address of an interface gets deleted, an alias of the interface (secondary) will be upgraded to become primary.
The default is to purge all the secondaries when you delete the primary
探索一下第二种方案。我们需要做如下的事情:
- 构造TCP协议的包
- 处理TCP-RST包
- 构造HTTP协议的包
然后我就找到了libcrafter这个库。