function gen_bits(ipaddr) { if (ipaddr.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) { var adr = ipaddr.split(/\./); if (adr[0] > 255 || adr[1] > 255 || adr[2] > 255 || adr[3] > 255) return 0; if (adr[0] == 0 && adr[1] == 0 && adr[2] == 0 && adr[3] == 0) return 0; if (adr[0] <= 127) return 23; else if (adr[0] <= 191) return 15; else return 7; } else return 0; }