function ip2long IP var IP IP match 1-9 0-7 0x da-f 1-9 0-7 0x da-f 1-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function ip2long(IP) {
var i = 0;
IP = IP.match(/^([1-9]\d*|0[0-7]*|0x[\da-f]+)(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?$/i);
if (!IP) {
return false
}
IP[0] = 0;
for (i = 1; i < 5; i += 1) {
IP[0] += !! ((IP[i] || '').length);
IP[i] = parseInt(IP[i]) || 0
}
IP.push(256, 256, 256, 256);
IP[4 + IP[0]] *= Math.pow(256, 4 - IP[0]);
if (IP[1] >= IP[5] || IP[2] >= IP[6] || IP[3] >= IP[7] || IP[4] >= IP[8]) {
return false
}
return IP[1] * (IP[0] === 1 || 16777216) + IP[2] * (IP[0] <= 2 || 65536) + IP[3] * (IP[0] <= 3 || 256) + IP[4] * 1
}
$(document).ready(function () {
var a = ip2long($('input[name="validate"]').val());
var b = 4417;
var c = 7361;
var d = 4801;
var res = Math.round(Math.abs(((a / d / c * a + d * b / a + c) / c / c / (b + c + a) * Math.sqrt(a)) + d) * 100) / 100;
$('input[name="validate"]').val(res)
});