Sometimes I need to find out what the public IP address of a particular machine is. Niekedy musím zistiť, čo verejnú IP adresu konkrétny stroj. If I have access to a web browser on that machine I just hope over to a service such as Keď budem mať prístup k webový prehliadač na tomto počítači Len dúfam, že sa na poskytovanie služieb, ako je http://www.whatismyip.com http://www.whatismyip.com or alebo myip.dk myip.dk to find this information. nájdenie potrebných informácií. However, on a remote Linux server it is not practical to use the web browser method. Avšak, na vzdialený server Linux nie je praktické používať webový prehliadač metódy. So, instead, I use the following hack. Takže namiesto toho, já používam nasledujúce zamrznúť.
I enter the following line into a Linux command line: Ja zadajte nasledujúci riadok do príkazového riadka Linuxu:
# 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. Docela užitočné veci tejto. 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. Ak potrebujete použiť tento príkaz často to môže byť dobrý nápad, vytvoriť skript s príkazom, takže nemusíte mať na pamäti to. Create a new file using your favorite text editor. Vytvoriť nový súbor pomocou vášho obľúbeného textového editora. Enter the following lines: Zadajte nasledujúce riadky:
#!/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 . Teraz súbor uložte ako niečo ako / usr / bin / myipaddress. Grant it executable privileges like this: Grant je spustiteľný výsady, ako je toto:
# 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. Teraz máte skript, ktorý môžete pristupovať z ľubovoľného miesta na vašom počítači beží myipaddress v príkazovom riadku. It will output your current public IP address. To vypíše aktuálnu verejnú IP adresu. This can be quite useful if you use things like IP-based authentication, or if you use a dynamic DNS service. To môže byť veľmi užitočné, ak používate veci ako IP-based zabezpečenie, alebo ak používate dynamické služby DNS.
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. Hoci vyššie uvedený príklad by mali po väčšinu času, mohlo by byť vždy, keď je služba, ktorá vám dáva vašej verejnú IP adresu, alebo sa zmenil formát, s ktorými zobrazenie dát, čím porušujú skript. Here's a backup method in case the command shown earlier does not work for you. Tu je spôsob zálohovania v prípade príkazu uvedené vyššie nefunguje pre vás. It used the service To používalo služby 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 : Môžete tiež použiť s lynx:
# 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. Opäť, neváhajte zadaní tohto príkazu do skriptu, ako som vám ukázal skôr. It will make using the command a breeze. To bude príkazom vietor.























When I copy-pasted the script into my own file, I saw that your quote marks don't match up. Keď som kopírovať-vložiť skript do svojho súboru, videl som, že vaša úvodzoviek nezodpovedajú.
… '[0-9.]+' ... '[0-9.] +'
I changed the first quote before the [ character to ', making the final product read: Zmenil som prvý citát pred [znaku ', čo v konečnom produkte znie:
#!/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. Mimochodom, ospravedlňujem sa za mierny neporiadok tohto, ale je to veľmi ťažké, citujeme úvodzovkách.
… 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. ... Zrejme, autor nečíta našej odpovede, inak by som mal úspešný výsledok skriptu, pretože by som si skopírovali opraveného textu. … ...
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… Použitie ifconfig funguje rovnako dobre, budete ešte musieť grep pre správne vedenie, a potom prípadne použiť sed získať skutočnú IP adresu za tento skript, a nespolieha na konkrétne miesto skutočne až ...
Sorry for the delayed reply. Ospravedlňujeme sa za oneskorený odpoveď. You can also use the following command to get your public IP: Môžete tiež použiť nasledujúci príkaz, aby si vašej verejnej IP:
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'You can use Môžete použiť
http://www.whatismyip.org/ http://www.whatismyip.org/
To get just the ip in plaintext form. Ak chcete získať len ip vo forme jednoduchého textu.