La séance de questions et réponses d’aujourd’hui nous est offerte par SuperUser, une sous-division de Stack Exchange, un groupe de sites Web de questions-réponses dirigé par la communauté.
Capture d'écran fournie par Paul Fenwick (Flickr).
La question
Le lecteur de superutilisateur AlikElzin-kilaka veut savoir comment trouver l’adresse IP d’un ordinateur à l’aide de la ligne de commande:
How do I find a computer’s internet (IP address) location using the command line? Would I use curl or wget, for example?
Comment trouver l’adresse IP d’un ordinateur à l’aide de la ligne de commande?
La réponse
Les contributeurs de SuperUser, AlikElzin-kilaka et Ben N, ont la solution pour nous. Tout d'abord, AlikElzin-kilaka:
There is a service (IPInfo) that can provide the results. You can invoke it using curl, for example:
curl ipinfo.io
Result:
curl ipinfo.io/216.58.194.46
Result:
Source: How to look up the geographic location of an IP address from the command line
Suivi de la réponse de 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):
(curl ipinfo.io).Content
Which produces a JSON string. To get the object that the JSON represents, use 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:
(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.
Avez-vous quelque chose à ajouter à l'explication? Sound off dans les commentaires. Voulez-vous lire plus de réponses d'autres utilisateurs de Stack Exchange doués en technologie? Découvrez le fil de discussion complet ici.