Here's a simple C++ program for converting IPs from dotted quad notation to decimal notation. I wrote this program for work to test a proxy we're setting up for public internet terminals.


#include <iostream.h>

main()
{
	// Initialize the variables
	unsigned long a,b,c,d,base10IP;

	// Get the IP address from user
	cout << "\nEnter an IP address in dotted quad notation (x.x.x.x)";
	cout << "\nwith each section seperated by a space: ";
	cin >> a >> b >> c >> d;

	// Do calculations to covert IP to base 10
	a *= 16777216;
	b *= 65536;
	c *= 256;
	base10IP = a + b + c + d;

	// Output new IP address
	cout << "\nThe converted address is: " << base10IP << '\n';
}

If you need a C++ compiler...

  • Windows: http://www.borland.com/bcppbuilder/freecompiler/
  • Linux: http://www.gnu.org/software/gcc/gcc.html
  • Mac OS X: http://developer.apple.com