我正在尝试监控我的公共 IP 和位置。我找到了一些命令可以帮助我找到我的公共 IP,但我找不到任何命令可以同时告诉我位置(国家、州、城市)。有谁能告诉我如何在终端中同时监控它们。提前致谢。
答案1
ipinfo.io
你可以尝试ipinfo.io在线服务。ipinfo.io提供基于 JSON 的地理位置 API。
尝试这个 :
curl ipinfo.io
以下是返回输出的示例:
{
"ip": "84.215.115.185",
"hostname": "snf-86437.vm.okeanos.grnet.gr",
"city": "Athens",
"region": "Attiki",
"country": "GR",
"loc": "37.9833,23.7333",
"org": "AS5408 Greek Research and Technology Network S.A"
}
地理IP
现在您可以安装 GeoIP,这是一个 C 库,可让您查找任何 IP 地址或主机名的来源国家/地区。它使用基于文件的数据库。
首先,你需要安装
geoip-数据库贡献
此软件包包含一个脚本,用于下载四个 MaxMind GeoLite 数据库(国家、IPv6 国家、城市和 ASN)的二进制版本的最新版本。
执行此命令来安装该包
sudo apt-get install geoip-database-contrib
执行此命令后,它会安装一个 cron 作业来更新 GeoLite 数据库。它位于
/etc/cron.d/geoip-database-contrib
因此,由于安装了所需的基于文件的数据库,如果我们想使用 geoiplookup 之类的命令行工具,我们必须安装另一个包。这个包名为 geoip-bin。执行
sudo apt-get install geoip-bin
现在你可以执行命令
geoiplookup google.com
以下是该工具返回的输出示例。
GeoIP Country Edition: US, United States
GeoIP City Edition, Rev 1: US, CA, Mountain View, 94043, 37.419201, -122.057404, 807, 650
GeoIP City Edition, Rev 0: US, CA, Mountain View, 94043, 37.419201, -122.057404
GeoIP ASNum Edition: AS15169 Google Inc.
要使用服务器的 IP 类型执行此命令:
geoiplookup $(curl ipv4.icanhazip.com)
笔记 :
需要注意的是,您的 IP 地址不属于您,属于您的 ISP 或服务提供商。因此,有关该 IP 地址的所有公开信息很可能只与他们有关。
答案2
使用下面的命令和一些 JSON:
首次安装jq
——轻量级且灵活的命令行 JSON 处理器
sudo apt-get install jq
现在启动下面的命令来获取你的公共 IP 的信息
curl --silent ipinfo.io | jq -r '.country,.region,.city'
特定 IP 地址(而非公共 IP)的示例
$ curl --silent ipinfo.io/8.8.8.8 | jq -r '.country,.region,.city'
US
California
Mountain View
答案3
任务几乎不可能完成。您的 IP 属于您的 ISP,您只能看到 ISP 注册数据,即 ISP 街道名称。只有当您注册某个网络范围时,才能获得更近的数据成熟但是你无法获得街道名称等精确的数据。
如果您使用来自 ISP 的动态公共网络范围,您将始终看到 ISP 数据或共享托管或...
例子:
host askubuntu.com
将逻辑名称重新解析为 ip
askubuntu.com has address 104.16.15.44
askubuntu.com has address 104.16.18.44
askubuntu.com has address 104.16.16.44
askubuntu.com has address 104.16.19.44
askubuntu.com has address 104.16.17.44
然后询问 whois 所有者
whois 104.16.15.44
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#
#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=104.16.15.44?showDetails=true&showARIN=false&showNonArinTopLevelNet=false&ext=netref2
#
NetRange: 104.16.0.0 - 104.31.255.255
CIDR: 104.16.0.0/12
NetName: CLOUDFLARENET
NetHandle: NET-104-16-0-0-1
Parent: NET104 (NET-104-0-0-0-0)
NetType: Direct Assignment
OriginAS: AS13335
Organization: CloudFlare, Inc. (CLOUD14)
RegDate: 2014-03-28
Updated: 2014-03-28
Comment: https://www.cloudflare.com
Ref: http://whois.arin.net/rest/net/NET-104-16-0-0-1
OrgName: CloudFlare, Inc.
OrgId: CLOUD14
Address: 665 Third Street #207
City: San Francisco
StateProv: CA
PostalCode: 94107
Country: US
RegDate: 2010-07-09
Updated: 2013-01-04
Comment: http://www.cloudflare.com/
Ref: http://whois.arin.net/rest/org/CLOUD14
OrgTechHandle: ADMIN2521-ARIN
OrgTechName: Admin
OrgTechPhone: +1-650-319-8930
OrgTechEmail: [email protected]
OrgTechRef: http://whois.arin.net/rest/poc/ADMIN2521-ARIN
OrgAbuseHandle: ABUSE2916-ARIN
OrgAbuseName: Abuse
OrgAbusePhone: +1-650-319-8930
OrgAbuseEmail: [email protected]
OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE2916-ARIN
OrgNOCHandle: NOC11962-ARIN
OrgNOCName: NOC
OrgNOCPhone: +1-650-319-8930
OrgNOCEmail: [email protected]
OrgNOCRef: http://whois.arin.net/rest/poc/NOC11962-ARIN
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#
对于来自NetRange: 104.16.0.0 - 104.31.255.255
您的任何 IP,都会看到相同的街道Address: 665 Third Street #207
示例 2:
whois 104.16.17.50
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#
#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=104.16.17.50?showDetails=true&showARIN=false&showNonArinTopLevelNet=false&ext=netref2
#
NetRange: 104.16.0.0 - 104.31.255.255
CIDR: 104.16.0.0/12
NetName: CLOUDFLARENET
NetHandle: NET-104-16-0-0-1
Parent: NET104 (NET-104-0-0-0-0)
NetType: Direct Assignment
OriginAS: AS13335
Organization: CloudFlare, Inc. (CLOUD14)
RegDate: 2014-03-28
Updated: 2014-03-28
Comment: https://www.cloudflare.com
Ref: http://whois.arin.net/rest/net/NET-104-16-0-0-1
OrgName: CloudFlare, Inc.
OrgId: CLOUD14
Address: 665 Third Street #207
City: San Francisco
StateProv: CA
PostalCode: 94107
Country: US
RegDate: 2010-07-09
Updated: 2013-01-04
Comment: http://www.cloudflare.com/
Ref: http://whois.arin.net/rest/org/CLOUD14
OrgTechHandle: ADMIN2521-ARIN
OrgTechName: Admin
OrgTechPhone: +1-650-319-8930
OrgTechEmail: [email protected]
OrgTechRef: http://whois.arin.net/rest/poc/ADMIN2521-ARIN
OrgAbuseHandle: ABUSE2916-ARIN
OrgAbuseName: Abuse
OrgAbusePhone: +1-650-319-8930
OrgAbuseEmail: [email protected]
OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE2916-ARIN
OrgNOCHandle: NOC11962-ARIN
OrgNOCName: NOC
OrgNOCPhone: +1-650-319-8930
OrgNOCEmail: [email protected]
OrgNOCRef: http://whois.arin.net/rest/poc/NOC11962-ARIN
#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml