Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IP address spoofing/changing for testing on local machine

Tags:

http

php

ip

I am trying to limit traffic to my website so that people trying to screenscrape mass amounts of data will be blocked after a while. I am supposed to do this based on the IPs of incoming requests. I believe I have the IP-limiting functionality written but, I'm stumped on how I can test it. I need to be able to change my IP address many times, to simulate valid traffic. I also need to test >20 different IPs, so a proxy solution for each one will not work for me.

I am testing the code on my local machine (running Ubuntu) so I can change my server settings (Apache) if I need to for this test.

I'm behind a corporate network so I cannot change MAC address/ARP settings to be "re-assigned" a new IP. I was hoping for some sort of localhost IP-changing type thing, so I could take advantage of the fact that the server and client were the same machine.

Also, I was trying to avoid changing the code before it is rolled out to production servers, but that may be the best way to do it.

How can I set this up?

like image 853
adept Avatar asked Nov 03 '25 09:11

adept


1 Answers

Well, what you could do is instead of actually checking the IP do something like this:

$ip = '1337.1337.1337.1337';

Instead of:

$ip = $_SERVER['REMOTE_ADDR']

And then go on to do your IP checking code.

So then when you are done you could make your $ip variable code look like this:

//$ip = '1337.1337.1337.1337';
$ip = $_SERVER['REMOTE_ADDR']

So you can easily turn on and off the "debug switch"

EDIT:

Or even make the IP dynamic:

$ips = Array('192.168.1.220', '120.843.592.86', '256.865.463.563');
$ip = $ips[rand(1,count($ips)-1)];
like image 90
unlobito Avatar answered Nov 06 '25 01:11

unlobito