Estas são algumas das opções para que você possa visualizar o IP Público via Terminal no Windows, Linux ou MAC.

É um ótima alternativa para que você possa inserir em seus scripts ou fazer apenas consulta para descobrir qual o IP Público sem sair do Terminal.

IP Público

3.234.140.184

BITS

set URL="http://myexternalip.com/raw"
bitsadmin /transfer "meuip" "%URL%" "%TEMP%"\meuip.txt
type "%TEMP%"\meuip.txt

cURL

curl ifconfig.me
curl icanhazip.com
curl ipecho.net/plain
curl ipinfo.io/ip
curl l2.io/ip
curl l2.io/ip.json?var=meuip
curl httpbin.org/ip
curl ipv4.icanhazip.com
curl ipv6.icanhazip.com
curl ident.me
curl v4.ident.me
curl v6.ident.me
curl checkip.amazonaws.com
curl rkeene.org/whatismyip
curl ipv4.rkeene.org/whatismyip
curl ipv6.rkeene.org/whatismyip
curl whatismyip.akamai.com
curl tnx.nl/ip
curl myip.dnsomatic.com
curl ip.appspot.com
curl ip.telize.com
curl curlmyip.com
curl api.ipify.org?format=json
curl api6.ipify.org?format=json
curl icanhazip.com
curl icanhazptr.com
curl icanhaztrace.com
curl icanhaztraceroute.com
curl -s checkip.dyndns.org | sed 's/.*IP Address: \([0-9\.]*\).*/\1/g'
curl -4 icanhazip.com
curl -6 icanhazip.com

dig

dig +short myip.opendns.com @resolver1.opendns.com
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'

exec

exec 3<> /dev/tcp/icanhazip.com/80 &&
echo 'GET /' >&3 &&
read -u 3 && echo $REPLY &&
exec 3>&- 

go

Crie o arquivo meuip.go com o conteúdo abaixo :

package main

import ( "io"; "net/http"; "os" )

func main() {
    resp, err := http.Get("http://myexternalip.com/raw")
    if err != nil {
        os.Stderr.WriteString(err.Error())
        os.Stderr.WriteString("\n")
        os.Exit(1)
    }
    defer resp.Body.Close()
    io.Copy(os.Stdout, resp.Body)
}

Execute o meuip.go

go run meuip.go

host

host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'

NodeJS

Crie o arquivo meuip.pl com o conteúdo abaixo :

var http = require('http');
var url = 'http://myexternalip.com/raw';
http.get(url, function(r) {
  r.setEncoding('utf8');
  r.on('data', console.log.bind(console));
});

Execute o meuip.js

node meuip.js

Crie o arquivo meuip2.pl com o conteúdo abaixo :

var request = require('request');
var url = 'http://myexternalip.com/raw';
request(url, function (err, resp, meuip) {
  console.log(meuip);
});

Execute o meuip2.js

node meuip2.js

npm

npm install --global public-ip-cli
public-ip

nslookup

nslookup myip.opendns.com resolver1.opendns.com

Perl

perl -e 'use LWP::Simple; $url = "http://myexternalip.com/raw"; print (get $url);'

Crie o arquivo meuip.pl com o conteúdo abaixo :

  • Instale o pacote apt-get install libwww-perl
#!/usr/bin/perl
use LWP::UserAgent;

my $useragent = new LWP::UserAgent();
my $meuip = $useragent->get('https://l2.io/ip')->content;
print 'Meu IP : '. $meuip;

Execute o meuip.pl

perl meuip.pl

PHP

php -r '$meuip = "http://myexternalip.com/raw";
echo file_get_contents($meuip);'

PowerShell

Invoke-RestMethod ipinfo.io/ip
(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
Invoke-RestMethod -Uri ('https://ipinfo.io/')
(Invoke-WebRequest ifconfig.me/ip).Content.Trim()
(((nslookup myip.opendns.com resolver1.opendns.com 2>null| select-string -pattern "Address:") -split ":")[3]).Trim()
[System.Net.Dns]::GetHostAddresses("www.google.com")[0] | Select IPAddressToString -ExpandProperty IPAddressToString
$meuip = new-object System.Net.WebClient
$url="http://myexternalip.com/raw"
$meuip.DownloadString($url)
$meuip = Invoke-WebRequest -URI http://myip.dnsomatic.com/
$meuip.Content

Python

import urllib
url = 'http://myexternalip.com/raw'
meuip = urllib.urlopen(url).read()
print meuip
import requests
url = 'http://myexternalip.com/raw'
meuip = requests.get(url)
ip = meuip.text
ip
from requests import get
meuip = get('https://l2.io/ip').text
print 'Meu IP : ', meuip

Ruby

Crie o arquivo meuip.rb com o conteúdo abaixo :

#!/usr/bin/ruby
require 'net/http'
require 'timeout'

secs_to_wait = ARGV[0].to_f || 10

begin
  Timeout::timeout(secs_to_wait) do
    response = Net::HTTP.get URI.parse('http://checkip.dyndns.org')
    puts response.match( /(?:Address: )([\d\.]+)/ )[1]
  end
rescue
  puts "Timeout: Unable to reach checkip.dyndns.org."
end

Execute o meuip.rb

ruby meuip.rb

Telnet

telnet ipecho.net 80
GET /plain HTTP/1.1
HOST: ipecho.net
BROWSER: web-kit
(enter)
(enter)

Shell

meuip=$(curl -s https://l2.io/ip)
echo "Meu IP : $meuip"

VB.Net

Dim wc as New System.Net.WebClient
Dim meuip as String = wc.DownloadString("https://l2.io/ip")

MessageBox.Show(meuip)

VBS

Crie o arquivo meuip.vbs com o conteúdo abaixo :

Option Explicit
Dim http : Set http = CreateObject( "MSXML2.ServerXmlHttp" )
http.Open "GET", "http://icanhazip.com", False
http.Send
Wscript.Echo http.responseText
Set http = Nothing

Execute o meuip.vbs

cscript meuip.vbs

WGet

wget -qO- icanhazip.com
wget -qO- ipecho.net/plain ; echo
wget -qO- ipecho.net/plain | xargs echo
wget -qO- myexternalip.com/raw

Você conhece outra forma?

Compartilhe comigo, envie um e-mail para : [email protected]



  Autor

Marcos Henrique

 São Paulo/SP



  Dicas

© 2020 - 100SECURITY

Contato