You have incorrect values 70.30.65.9 will correspond with 1176387849 but never with 9766322441.
C++ Example of converting IP to decimal:
#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 convert 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';
}
This is JAVA class to convert IP to decimal:
-
/**
* @author Charles Johnson
* from http://www.technojeeves.com/joomla/index.php/free/58-convert-ip-address-to-number
*/
public class IpConverter {
public static void main(String[] args) {
System.out.println(longToIp(Long.valueOf(args[0], 16)));
}
public static String toHex(String ipAddress) {
return Long.toHexString(IpConverter.ipToLong(ipAddress));
}
public static long ipToLong(String ipAddress) {
long result = 0;
String[] atoms = ipAddress.split("\\.");
for (int i = 3; i >= 0; i--) {
result |= (Long.parseLong(atoms[3 - i]) << (i * 8));
}
return result & 0xFFFFFFFF;
}
public static String longToIp(long ip) {
StringBuilder sb = new StringBuilder(15);
for (int i = 0; i < 4; i++) {
sb.insert(0, Long.toString(ip & 0xff));
if (i < 3) {
sb.insert(0, '.');
}
ip >>= 8;
}
return sb.toString();
}
}
Another JAVA example to convert IP to decimal:
-
String ip="70.30.65.9";
String[] addrArray = ip.split("\.");
long num = 0;
for (int i = 0; i
PHP function to convert IP to decimal:
-
function myip2long($ip) {
if (is_numeric($ip)) {
return sprintf( "%u", floatval($ip) );
} else {
return sprintf( "%u", floatval(ip2long($ip) ));
}
}
Try applying it, e.g.:
echo myip2long("192.168.1.1");
Another example in PHP to convert IP to decimal:
-
function myip2long2($ip){
$d = 0.0;
$b = explode(".", $ip,4);
for ($i = 0; $i
PHP example to convert decimal to IP:
-
function customLong2ip($ip){
$b=array(0,0,0,0);
$c = 16777216.0;
$ip += 0.0;
for ($i = 0; $i