https://github.com/netpi/ip2bit
https://github.com/netpi/ip2bit
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/netpi/ip2bit
- Owner: netpi
- Created: 2017-06-02T08:33:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-05T06:18:33.000Z (almost 8 years ago)
- Last Synced: 2025-02-04T15:48:29.755Z (3 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## ip2bit
> node >= 6.0.0
### Directory Structure
```sh
├── lib
│ └── ip2bit.js
├── package.json
├── readme.md
├── test
│ └── ip2bit.test.js
└── yarn.lock
```
### Test```sh
yarn test
# or
npm run test# 测试代码覆盖率
yarn cov
```
### example
```js
const ip2bit = require('../lib/ip2bit')
let ip = '172.168.5.1'
console.log(ip, ip2bit.to32bit(ip)) // 2896692481ip = '172. 168 .5.1'
console.log('ip', ip2bit.to32bit(ip)) // 2896692481ip = '1 72.168.5.1'
try {
ip2bit.to32bit(ip)
} catch (e) {
console.log(ip, 'some error with [1 72.168.5.1]')
}ip = '错误.IP.5.1'
try {
ip2bit.to32bit(ip)
} catch (e) {
console.log(ip, 'some error with [错误.IP.5.1]')
}ip = '256.12.5.1' // > 255
try {
ip2bit.to32bit(ip)
} catch (e) {
console.log(ip, 'some error with [256.12.5.1]')
}```