Note that there are some explanatory texts on larger screens.

plurals
  1. POGet my public IP using netcat
    primarykey
    data
    text
    <p>I have a very basic Linux server running on an IP camera (Busybox). I'd like to get the public IP of that camera, which is located behind a router. It has no "wget" nor "traceroute", and "ping" is just answering "alive" or "not alive"...</p> <p>The only one available is a basic "netcat" :</p> <pre><code>nc BusyBox v1.1.3 (2009.12.07-16:16+0000) multi-call binary Usage: nc [OPTIONS] [IP] [port] Netcat opens a pipe to IP:port Options: -l listen mode, for inbound connects -p PORT local port number -i SECS delay interval for lines sent -w SECS timeout for connects and final net reads -4 Use IPv4 (default) -6 Use IPv6 -D DSCP set IP DSCP field -P PRIO set VLAN user-priority </code></pre> <p>Provided my ISP allows outgoing HTTP, is it possible to use netcat in order to get the public IP response from a site like www.obtainip.com or similar ?</p> <p>GREAT and many thanks to both of you guys as I did not feel comfortable with nc at all.</p> <p>Here are the 2 working ways :</p> <pre><code>echo "GET /automation/n09230945.asp HTTP/1.0" &gt; http_req2.txt echo "Host: www.whatismyip.com" &gt;&gt; http_req2.txt echo "" &gt;&gt; http_req2.txt echo "" &gt;&gt; http_req2.txt IP2=$(cat http_req2.txt | nc www.whatismyip.com 80 | tail -n 1) echo $IP2 YEAH ! </code></pre> <p>and more strange but... it also works :</p> <pre><code>echo "GET / HTTP/1.0" &gt; http_request.txt echo "Host: www.whatismyip.com" &gt;&gt; http_request.txt echo "User-Agent: netcat" &gt;&gt; http_request.txt echo "Referer: http://www.whatismyip.com/" &gt;&gt; http_request.txt echo "" &gt;&gt; http_request.txt echo "" &gt;&gt; http_request.txt IP=$(cat http_request.txt | nc www.whatismyipaddress.com 80 | tail -n 1) echo $IP YEAH again! </code></pre> <p>EDIT Of course, this can be scripted better like suggested :</p> <pre><code>echo -e "GET /automation/n09230945.asp HTTP/1.0\n"Host: www.whatismyip.com\n\n" | nc www.whatismyipaddress.com 80 | tail -n 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload