bench程序增加对sip、eip合法性检测

This commit is contained in:
Wu Jian Ping
2022-07-22 14:05:04 +08:00
parent 609e7749ee
commit bd084c0a5d
2 changed files with 19 additions and 2 deletions

View File

@@ -86,9 +86,21 @@ const main = async () => {
const list = line.split('|')
const sip = list[0]
const eip = list[1]
if (!Searcher.isValidIp(sip)) {
throw new Error(`IP: ${sip} is invalid`)
}
if (!Searcher.isValidIp(eip)) {
throw new Error(`IP: ${eip} is invalid`)
}
const sipInt = ipToInt(sip)
const eipInt = ipToInt(eip)
if (sipInt > eipInt) {
throw new Error(`start ip(${sip}) should not be greater than end ip(${eip})`)
}
const mipInt = Math.floor((sipInt + eipInt) / 2)
const mip = intToIp(mipInt)