lionsoul2014/ip2region · error · Error
invalid ipv4 address
Error message
invalid ipv4 address
What it means
Validation guard inside the IPv4 parser: the input was routed here because it contained a dot and no colon, but splitting on '.' did not yield exactly 4 octets (e.g. '1.2.3' or '1.2.3.4.5'). The address is structurally not dotted-quad IPv4.
Source
Thrown at binding/javascript/util.js:54
toString() {
return `{
"version":${this.version},
"index_policy":${this.indexPolicy},
"start_index_ptr": ${this.startIndexPtr},
"end_index_ptr": ${this.endIndexPtr},
"ipVersion": ${this.ipVersion},
"runtime_ptr_bytes": ${this.runtimePtrBytes}
}`;
}
}
// ---
// parse ipv4 address
function _parse_ipv4_addr(v4String) {
let ps = v4String.split('.', 4);
if (ps.length != 4) {
throw new Error('invalid ipv4 address');
}
var v;
const ipBytes = Buffer.alloc(4);
for (var i = 0; i < ps.length; i++) {
v = parseInt(ps[i], 10);
if (isNaN(v)) {
throw new Error(`invalid ipv4 part '${ps[i]}', a valid number expected`);
}
if (v < 0 || v > 255) {
throw new Error(`invalid ipv4 part '${ps[i]}' should >= 0 and <= 255`);
}
ipBytes[i] = (v & 0xFF);
}
return ipBytes;View on GitHub (pinned to c1a1fc7d59)
Solutions
- Supply a well-formed dotted-quad IPv4 address such as '1.2.3.4'
- Validate the string with a regex or net.isIPv4 before calling search/parseIP
- If the input is actually IPv6, remove the dots or pass the v6 string to a v6-capable searcher
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at binding/javascript/util.js:54 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02).
Data as JSON: /api/errors/0032a6c968b29845.
Report an issue: GitHub.