Sometimes I need to find out what the public IP address of a particular machine is. Noen ganger jeg må finne ut hva den offentlige IP-adressen til en bestemt maskin er. If I have access to a web browser on that machine I just hope over to a service such as Hvis jeg har tilgang til en nettleser på at maskinen Jeg håper bare over til en tjeneste som http://www.whatismyip.com http://www.whatismyip.com or eller myip.dk myip.dk to find this information. å finne denne informasjonen. However, on a remote Linux server it is not practical to use the web browser method. Men på en ekstern Linux server er det ikke praktisk å bruke nettleseren metoden. So, instead, I use the following hack. Så i stedet bruker jeg fulgte banalisere.
I enter the following line into a Linux command line: Jeg skriver inn følgende linje i en Linux kommandolinje:
# curl -s myip.dk | grep '"Box"' | egrep -o '[0-9.]+' # Curl-s myip.dk | grep ' "Box"' | egrep-o '[0-9.] +'
122.172.9.222 122.172.9.222
Pretty useful stuff this. Ganske nyttig ting dette. If you need to use this command often it might be a good idea to create a script with the command so that you need not have to remember it. Hvis du må bruke denne kommandoen ofte det kan være en god idé å lage et script med kommandoen slik at du trenger ikke å huske det. Create a new file using your favorite text editor. Opprett en ny fil med din favoritt teksteditor. Enter the following lines: Skriv inn følgende linjer:
#!/bin/bash #! / bin / bash
curl -s myip.dk | grep '"Box"' | egrep -o '[0-9.]+' curl-s myip.dk | grep ' "Box"' | egrep-o '[0-9.] +'
Now save the file as something like /usr/bin/myipaddress . Nå lagre filen som noe som / usr / bin / myipaddress. Grant it executable privileges like this: Grant det startbar privilegier slik:
# chmod +x /usr/bin/myipaddress # Chmod + x / usr / bin / myipaddress
Now you have a script that you can access from anywhere on your computer by running myipaddress in the command line. Nå har du et skript som du kan få tilgang fra hvor som helst på datamaskinen din ved å kjøre myipaddress i kommandolinjen. It will output your current public IP address. Det vil produksjonen din nåværende offentlige IP-adressen. This can be quite useful if you use things like IP-based authentication, or if you use a dynamic DNS service. Dette kan være ganske nyttig hvis du bruker ting som IP-basert autentisering, eller hvis du bruker en dynamisk DNS-tjeneste.
Although the above example should work most of the time, there might be times when the service that gives you your public IP address is down or has changed the format with which they display the data, thus breaking the script. Selv om eksemplet ovenfor skal jobbe mesteparten av tiden, kan det være ganger når tjenesten som gir deg din offentlige IP-adressen er nede eller har endret formatet som de vise data, og dermed bryte skriptet. Here's a backup method in case the command shown earlier does not work for you. Her er en backup metode i tilfelle kommandoen vist tidligere ikke fungerer for deg. It used the service Den brukte tjenesten http://www.formyip.com/ http://www.formyip.com/ . .
# links -dump http://www.formyip.com/ | awk "/IP is/{print $NF}" # Links-dump http://www.formyip.com/ | awk "/ IP / (print $ NF)"
You could also use this with lynx : Du kan også bruke dette med gaupe:
# lynx -dump http://www.formyip.com/ | awk "/IP is/{print $NF}" # Lynx-dump http://www.formyip.com/ | awk "/ IP / (print $ NF)"
Again, feel free to enter this command into a script like I showed you earlier. Igjen gjerne inn denne kommandoen i et script som jeg viste dere tidligere. It will make using the command a breeze. Det vil gjøre ved hjelp av kommandoen til en lek.























When I copy-pasted the script into my own file, I saw that your quote marks don't match up. Når jeg kopierer limes skriptet inn i min egen fil, så jeg at tilbudet merker ikke samsvarer.
… '[0-9.]+' ... '[0-9.] +'
I changed the first quote before the [ character to ', making the final product read: Jeg har forandret den første quote før [tegn til ", noe som gjør det endelige produktet lyde:
#!/bin/bash #! / bin / bash
curl -s myip.dk | grep '"Box"' | egrep -o '[0-9.]+' curl-s myip.dk | grep ' "Box"' | egrep-o '[0-9.] +'
By the way, I apologize for the slight messiness of this, but it's very difficult to quote a quote mark. Forresten, beklager jeg for svak messiness av dette, men det er veldig vanskelig å sitere en anførselstegn.
… evidently, the author doesn't read our replies, otherwise, I'd have had a successful execution of the script file, because I would have copied corrected text. ... Tydeligvis, ikke forfatteren ikke lese våre svar, ellers hadde jeg hatt en vellykket gjennomføring av skriptfil, fordi jeg ville ha kopiert korrigert tekst. … ...
Using ifconfig works just as well, you'll still need to grep for the proper lines, and then possibly use sed to extract the actual IP address as this script does, and it doesn't rely on a specific site actually being up… Bruk ifconfig fungerer like bra, vil du likevel må grep for den riktige linjer og eventuelt bruke sed å trekke selve IP-adressen som dette skriptet gjør, og ikke stole på et bestemt område faktisk opp ...
Sorry for the delayed reply. Sorry for den forsinkede svar. You can also use the following command to get your public IP: Du kan også bruke følgende kommando for å få din offentlige IP:
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'You can use Du kan bruke
http://www.whatismyip.org/ http://www.whatismyip.org/
To get just the ip in plaintext form. For å få akkurat den ip i klarteksten form.