mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
更换ip地址查询接口
This commit is contained in:
parent
930541d5d6
commit
8cef0b6216
|
@ -1,6 +1,7 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import got from 'got';
|
||||
import iconv from 'iconv-lite';
|
||||
|
||||
export function getFileContentByName(fileName: string) {
|
||||
if (fs.existsSync(fileName)) {
|
||||
|
@ -156,18 +157,24 @@ export async function getNetIp(req: any) {
|
|||
ip = '';
|
||||
}
|
||||
try {
|
||||
const baiduApi = got.get(
|
||||
`https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=${ip}&co=&resource_id=6006&t=1555898284898&ie=utf8&oe=utf8&format=json&tn=baidu`,
|
||||
);
|
||||
const ipApi = got.get(
|
||||
`https://whois.pconline.com.cn/ipJson.jsp?ip=${ip}&json=true`,
|
||||
);
|
||||
const [{ data }, { addr, region, city }] = await (
|
||||
await Promise.all<any>([baiduApi, ipApi])
|
||||
).map((x) => JSON.parse(x.body));
|
||||
if (data[0] && data[0].location) {
|
||||
return { address: data[0].location, ip };
|
||||
} else if (city && region) {
|
||||
const baiduApi = got
|
||||
.get(`https://www.cip.cc/${ip}`, { timeout: 100000 })
|
||||
.text();
|
||||
const ipApi = got
|
||||
.get(`https://whois.pconline.com.cn/ipJson.jsp?ip=${ip}&json=true`, {
|
||||
timeout: 100000,
|
||||
})
|
||||
.buffer();
|
||||
const [data, ipApiBody] = await await Promise.all<any>([baiduApi, ipApi]);
|
||||
|
||||
const ipRegx = /.*IP :(.*)\n/;
|
||||
const addrRegx = /.*数据二 :(.*)\n/;
|
||||
if (data && ipRegx.test(data) && addrRegx.test(data)) {
|
||||
const ip = data.match(ipRegx)[1];
|
||||
const addr = data.match(addrRegx)[1];
|
||||
return { address: addr, ip };
|
||||
} else if (ipApiBody) {
|
||||
const { addr, ip } = JSON.parse(iconv.decode(ipApiBody, 'GBK'));
|
||||
return { address: `${addr}`, ip };
|
||||
} else {
|
||||
return { address: `获取失败`, ip };
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
"express-jwt": "^6.0.0",
|
||||
"express-urlrewrite": "^1.4.0",
|
||||
"got": "^11.8.2",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lodash": "^4.17.21",
|
||||
"nedb": "^1.8.0",
|
||||
|
|
|
@ -29,6 +29,7 @@ specifiers:
|
|||
express-jwt: ^6.0.0
|
||||
express-urlrewrite: ^1.4.0
|
||||
got: ^11.8.2
|
||||
iconv-lite: ^0.6.3
|
||||
jsonwebtoken: ^8.5.1
|
||||
lint-staged: ^10.0.7
|
||||
lodash: ^4.17.21
|
||||
|
@ -68,6 +69,7 @@ dependencies:
|
|||
express-jwt: 6.0.0
|
||||
express-urlrewrite: 1.4.0
|
||||
got: 11.8.2
|
||||
iconv-lite: 0.6.3
|
||||
jsonwebtoken: 8.5.1
|
||||
lodash: 4.17.21
|
||||
nedb: 1.8.0
|
||||
|
@ -4282,7 +4284,6 @@ packages:
|
|||
engines: {node: '>=0.10.0'}
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
dev: true
|
||||
|
||||
/identity-obj-proxy/3.0.0:
|
||||
resolution: {integrity: sha1-lNK9qWCERT7zb7xarsN+D3nx/BQ=}
|
||||
|
|
Loading…
Reference in New Issue
Block a user