hyp*_*ium 6 ip webserver android android-networking hotspot
我想将安卓手机设置为 wifi 热点,然后在其上运行网络服务器,并从连接到热点的另一部手机浏览它。
我的手机没有 root,但我有termux,它有很多 unix 实用程序。我不想安装额外的应用程序。(但很高兴写一个!)
我可以在http://localhost(在主机上)查看 python 的简单网络服务器,但不能在另一部手机上查看。我尝试使用主机电话的面向公众的 IP(使用 whatsmyip 类型的网页检查它),但没有用。有人说移动 ISP 通过映射不同的内部和外部 IP 来防止这种情况……但在这里,它不是通过 ISP,而是通过热点……
我还尝试了来自ifconfig和来自 android 中的 wifi 控件的IP 地址,这确实适用netcat- 但只有连接到热点(而不是主机)的客户端电话的 IP。
也就是说,netcat在连接到netcat热点的手机上收听,然后在热点手机上连接到它。(ierole 交换:热点客户端是 netcat 服务器)。古怪,热点电话似乎并不具有一个IP(至少,不是一个我已经能够发现,到目前为止)。但它必须有一个,不是netcat吗,为了连接......?
无论如何,我想要热点主机上的网络服务器,所以我需要它的IP来连接它......有没有办法得到它?
这一直困扰着我多年。非常感谢您的帮助!
编辑这个问题的答案说它(几乎)总是 192.168.43.1。我现在无法尝试;我有时会更新。
更新
1.192.168.43.1工作
2.py http.server适用于常规文件(例如 txt、pdf),但视频文件似乎需要一些它缺少的流媒体协议。我发现lighttpd有这个(在termuxusing 中可用apt install lighttpd)。但它需要配置(没有eg/default)。我用了:
$ cat > lighttp.conf
dir-listing.activate = "enable"
server.port = 8000
server.document-root = "MY PATH HERE"
$ lighttpd -D -f lighttpd.conf
Run Code Online (Sandbox Code Playgroud)
目录列表使它更容易使用,但显然这里没有配置安全性,所以要小心你提供的内容。
3. Android(我的 5.1,无论如何)需要关闭飞行模式才能使其成为 wifi 热点 - 这对互联网访问有意义......但在这里,我只希望客户端可以访问主机,而不是可以访问它到整个互联网。所以我发现你可以关闭数据访问来防止这种情况,热点仍然有效。(肯定有一种方法可以以编程方式在飞行模式下设置热点...)
你有它!电话作为媒体服务器。
public static String getDeviceIpAddress( ) {
String deviceIpAddress = "###.###.###.###";
try {
for (Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); enumeration.hasMoreElements();) {
NetworkInterface networkInterface = enumeration.nextElement();
for (Enumeration<InetAddress> enumerationIpAddr = networkInterface.getInetAddresses(); enumerationIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumerationIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress.getAddress().length == 4)
{
deviceIpAddress = inetAddress.getHostAddress();
Log.e(TAG, "deviceIpAddress: " + deviceIpAddress);
}
}
}
} catch (SocketException e) {
Log.e(TAG, "SocketException:" + e.getMessage());
}
return deviceIpAddress;
}
Run Code Online (Sandbox Code Playgroud)
我想这会对你有帮助。
| 归档时间: |
|
| 查看次数: |
3660 次 |
| 最近记录: |