gpt4 book ai didi

ip - 使用 netcat 获取我的公共(public) IP

转载 作者:行者123 更新时间:2023-12-01 02:42:00 24 4
gpt4 key购买 nike

我有一个非常基本的 Linux 服务器,在 IP 摄像机 (Busybox) 上运行。我想获取该摄像机的公共(public) IP,它位于路由器后面。它没有“wget”也没有“traceroute”,“ping”只是回答“alive”或“not alive”...

唯一可用的是基本的“netcat”:

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

如果我的 ISP 允许传出 HTTP,是否可以使用 netcat 从 www.obtainip.com 或类似网站获取公共(public) IP 响应?

非常好,非常感谢你们两个,因为我对 nc 一点都不满意。

这里有两种工作方式:

echo "GET /automation/n09230945.asp HTTP/1.0" > http_req2.txt
echo "Host: www.whatismyip.com" >> http_req2.txt
echo "" >> http_req2.txt
echo "" >> http_req2.txt
IP2=$(cat http_req2.txt | nc www.whatismyip.com 80 | tail -n 1)
echo $IP2
YEAH !

还有更奇怪的,但是......它也有效:

echo "GET / HTTP/1.0" > http_request.txt
echo "Host: www.whatismyip.com" >> http_request.txt
echo "User-Agent: netcat" >> http_request.txt
echo "Referer: http://www.whatismyip.com/" >> http_request.txt
echo "" >> http_request.txt
echo "" >> http_request.txt
IP=$(cat http_request.txt | nc www.whatismyipaddress.com 80 | tail -n 1)
echo $IP
YEAH again!

编辑当然,这可以像建议的那样更好地编写脚本:

echo -e "GET /automation/n09230945.asp HTTP/1.0\n"Host: www.whatismyip.com\n\n" | nc www.whatismyipaddress.com 80 | tail -n 1

最佳答案

由于 whatismyip.com 的自动化功能下降,这里有一个替代方案:

$ echo GET / | nc icanhazip.com 80

...这将输出你的IP。

关于ip - 使用 netcat 获取我的公共(public) IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4253237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com