I do a lot of local development with Internet Information Services and either ColdFusion, PHP or ASP.net and for the longest time I would actually run the websites on separate ports on 127.0.0.1.
Unfortunately running multiple websites on various other ports causes some issues like:
- Port conflicts with other programs
- Remembering which port is used for what website
- Causes problems with some websites that look for port 80
- Doesn’t really work with SSL (port 443)
So what I started doing was running my websites on separate private IP addresses which are local to my machine only, and this worked GREAT! I could load up websitexyz, bind it to IP 220.127.116.11, setup SSL to work on port 443 for 18.104.22.168 and I would go about my business.
The only downside was when I would run out of IP addresses, because I would only add about 5 to 10 IPs at a time to my local loopback adapter. It is a bit of a pain in the butt to add a bunch of IP addresses in Windows, so it would take me a bit of time to do this everytime I needed more IPs.
That was until I ran into a small batch script which can add as many IP addresses as I want in a range.
Here’s the code:
FOR /L %A IN (41,1,100) DO netsh interface ipv4 add address “ColdFusion-IIS” 1.1.1.%A 255.255.255.0
Simply copy that into either a command prompt or a .bat file and run it to add as many IP addresses in a range that you want.
Here’s the break down of the script:
FOR /L %A IN (START,INCREMENT,END) DO netsh interface ipv4 add address “INTERFACE_NAME” IPMASK SUBNET
If we take a look at my script above we see that
- START = 41
- INCREMENT = 1
- END = 100
- INTERFACE_NAME = ColdFusion-IIS
- IPMASK = 1.1.1.%A
- SUBNET = 255.255.255.0
What this basically equates to is adding 22.214.171.124 to 126.96.36.199 to my network adapter called ColdFusion-IIS.