命令行查找包位置_如何使用命令行查找计算机的地理位置?

命令行查找包位置

命令行查找包位置_如何使用命令行查找计算机的地理位置?

There are many ways to learn the location of a computer from its IP address, but how do you go about it if you decide to use the command line to find the information? Today’s SuperUser Q&A post has some helpful suggestions to help a reader find the information he wants.

有很多方法可以从IP地址了解计算机的位置,但是如果决定使用命令行查找信息,该如何处理呢? 今天的SuperUser Q&A帖子提供了一些有用的建议,以帮助读者找到所需的信息。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

Screenshot courtesy of Paul Fenwick (Flickr).

屏幕截图由Paul Fenwick(Flickr)提供

问题 (The Question)

SuperUser reader AlikElzin-kilaka wants to know how to find a computer’s IP address location using the command line:

超级用户阅读器AlikElzin-kilaka想知道如何使用命令行查找计算机的IP地址位置:

How do I find a computer’s internet (IP address) location using the command line? Would I use curl or wget, for example?

如何使用命令行查找计算机的Internet(IP地址)位置? 例如,我会使用curl还是wget?

How do you find a computer’s IP address location using the command line?

如何使用命令行查找计算机的IP地址位置?

答案 (The Answer)

SuperUser contributors AlikElzin-kilaka and Ben N have the answer for us. First up, AlikElzin-kilaka:

超级用户贡献者AlikElzin-kilaka和Ben N为我们找到了答案。 首先,AlikElzin-kilaka:

There is a service (IPInfo) that can provide the results. You can invoke it using curl, for example:

有一个可以提供结果的服务( IPInfo )。 您可以使用curl调用它,例如:

  • curl ipinfo.io

    卷曲ipinfo.io

Result:

结果:

命令行查找包位置_如何使用命令行查找计算机的地理位置?

A specific IP’s info can also be requested:

还可以请求特定IP的信息:

  • curl ipinfo.io/216.58.194.46

    卷曲ipinfo.io/216.58.194.46

Result:

结果:

命令行查找包位置_如何使用命令行查找计算机的地理位置?

Source: How to look up the geographic location of an IP address from the command line

来源:如何从命令行查找IP地址的地理位置

Followed by the answer from Ben N:

随后是Ben N的回答:

Since the question does not specify an operating system, this is how to get that same information with PowerShell’s curl (actually an alias of Invoke-WebRequest):

由于该问题未指定操作系统,因此这是如何通过PowerShell的curl(实际上是Invoke-WebRequest的别名)获取相同的信息:

  • (curl ipinfo.io).Content

    (curl ipinfo.io)。内容

Which produces a JSON string. To get the object that the JSON represents, use ConvertFrom-Json:

产生一个JSON字符串。 要获取JSON表示的对象,请使用ConvertFrom-Json

  • curl ipinfo.io | ConvertFrom-Json

    curl ipinfo.io | ConvertFrom-Json

Since that is a PowerShell object, you can easily get specific fields from it. For example, this command gets just the external IP address as a string:

由于这是一个PowerShell对象,因此您可以轻松地从中获取特定字段。 例如,以下命令仅将外部IP地址作为字符串获取:

  • (curl ipinfo.io | ConvertFrom-Json).ip

    (curl ipinfo.io | ConvertFrom-Json).ip

Note that the geographical information from this service is not super accurate, but it did locate me within 20 miles or so of my actual location and the ISP information seems to be reliable.

请注意,此服务提供的地理信息不是非常准确,但是它确实将我定位在距我实际位置约20英里的范围内,并且ISP信息似乎是可靠的。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/252070/how-do-you-find-a-computers-geographic-location-using-the-command-line/

命令行查找包位置

相关文章: