Browse Source

fix: several problems

master
Dnomd343 4 years ago
parent
commit
194e340867
  1. 50
      README.md
  2. 2
      assets/js/main.js
  3. 2
      assets/js/main.min.js
  4. 6
      backend/country.php
  5. 7
      backend/queryInfo.php
  6. 2
      conf/nginx/docker.conf
  7. 2
      conf/nginx/ip.conf
  8. 8
      error.html

50
README.md

@ -28,7 +28,7 @@ shell> curl ip.343.re/8.8.8.8
···
```
![echoIP-cli](https://pic.dnomd343.top/images/aDE.png)
![echoIP-cli](https://pic.dnomd343.top/images/pkr.png)
### 网页访问模式
@ -42,6 +42,8 @@ shell> curl ip.343.re/8.8.8.8
### Docker方式
echoIP支持Docker容器部署,在[Docker Hub](https://hub.docker.com/repository/docker/dnomd343/echoip)或[Github Package](https://github.com/dnomd343?tab=packages&repo_name=echoIP)有打包完成的镜像下载。
确定你的服务器上有Docker环境
```
@ -218,6 +220,52 @@ shell> docker run -dit --name echoip -p 1601:8080 echoip
shell> docker exec -it echoip bash
```
### 部分接口
1. echoIP支持在URL中指定查询目标IP,格式形如 `https://ip.343.re?ip=1.2.3.4`,访问时自动显示该IP地址的信息。
2. echoIP后端支持返回当前版本信息,接口位于 `/version` 下,若请求来自命令行,则返回可视化格式,否则返回JSON数据。
```
shell> curl ip.343.re/version
echoip -> v1.1
qqwry.dat -> 2021-04-21
ipip.net -> 2019-07-03
shell> curl https://ip.343.re/version --user-agent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.42'
{"echoip":"v1.1","qqwry.dat":"20210421","ipip.net":"20190703"}
```
3. echoIP后端统一接口为 `/query`,可请求以下参数
```
error -> 请求出错
version -> 获取版本数据
cli -> 来自命令行下的请求
justip -> 仅查询IP地址
ip -> 请求指定IP的数据
```
示例
```
shell> curl "ip.343.re/query?justip=true"
{"ip":"116.57.98.121"}
shell> curl "ip.343.re/query?justip=true&cli=true"
116.57.98.124
shell> curl "ip.343.re/query?cli=true&ip=7.7.7.7"
IP: 7.7.7.7
AS: AS8003
City: Atlantic City
Region: New Jersey
Country: US - United States(美国)
Timezone: America/New_York
Location: 39.3642,-74.4231
ISP: Global Resource Systems, LLC
Scope: 7.0.0.0/8
Detail: 美国俄亥俄州哥伦布市DoD网络信息中心
```
### ipinfo.io
在线请求,格式为 `https://ipinfo.io/$IP/json`,返回指定IP对应的信息,形如:

2
assets/js/main.js

@ -14,7 +14,7 @@ $(document).ready(function() {
$("button").text("Searching...");
$("table").hide(1000);
$("input").val(trim($("input").val()));
if (checkIP($("input").val()) == "ok") {
if ($("input").val() == '' || checkIP($("input").val()) == "ok") {
getInfo();
} else {
errorIP();

2
assets/js/main.min.js

File diff suppressed because one or more lines are too long

6
backend/country.php

@ -15,18 +15,18 @@ class countryDB extends SQLite3 {
}
}
function getCountry($code) { // 根据两位国家代码获取英文与中文全称
function getCountry($code) { // 根据两位国家代码获取英文与中文全称
if ($code == null) {
return null;
}
$db = new countryDB;
$raw = $db->query('SELECT * FROM main WHERE alpha_2="'.$code.'";')->fetchArray(SQLITE3_ASSOC);
$raw = $db->query('SELECT * FROM main WHERE alpha_2=\'' . $code . '\';')->fetchArray(SQLITE3_ASSOC);
$data['code'] = $code;
if ($raw) {
$data['en'] = $raw['name_en'];
$data['cn'] = $raw['name_cn'];
} else {
$data['en'] = "Unknow";
$data['en'] = null;
$data['cn'] = null;
}
return $data;

7
backend/queryInfo.php

@ -31,8 +31,11 @@ function getIPInfo($ip) {
$info['city'] = $data['city'];
$info['region'] = $data['region'];
if (isset($data['country'])) {
$info['country'] = $data['country'] . ' - ' . $country['en'];
$info['country'] .= "(" . $country['cn'] . ")";
$info['country'] = $data['country'];
if (isset($country['en'])) {
$info['country'] .= ' - ' . $country['en'];
$info['country'] .= "(" . $country['cn'] . ")";
}
}
$info['timezone'] = $data['timezone'];
$info['loc'] = $data['loc'];

2
conf/nginx/docker.conf

@ -2,7 +2,7 @@ server {
listen 8080;
root /var/www/echoIP;
error_page 403 404 500 501 502 503 504 = /error.html;
error_page 403 404 = /error.html;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Real-IP;

2
conf/nginx/ip.conf

@ -27,7 +27,7 @@ server {
listen 127.0.0.1:1601;
root /var/www/echoIP;
error_page 403 404 500 501 502 503 504 = /error.html;
error_page 403 404 = /error.html;
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Real-IP;

8
error.html

@ -8,8 +8,8 @@
<title>Dnomd343 - IP</title>
<link href="assets/error/css/style.css" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="assets/img/favicon.png">
<link href="/assets/error/css/style.css" rel="stylesheet">
<link rel="shortcut icon" type="image/png" href="/assets/img/favicon.png">
<noscript>
<style>
@ -36,7 +36,7 @@
<div class="row">
<div class="col-sm-5">
<div class="ghost">
<a href="/" class="body" target="_self">
<a href="/" class="body" target="_self" title="Back to homepage">
<i class="icon icon-flickr"></i>
</a>
</div>
@ -54,7 +54,7 @@
Typekit.load();
} catch(e) {}
</script>
<script src="assets/error/js/custom.js"></script>
<script src="/assets/error/js/custom.js"></script>
</body>
</html>

Loading…
Cancel
Save