android热点上的webserver - 它的IP是什么? [英] webserver on an android hotspot - what's its IP?

查看:282
本文介绍了android热点上的webserver - 它的IP是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Android手机设置为wifi热点,然后在其上运行网络服务器,并从连接到热点的另一部手机浏览。

I want to setup an android phone as a wifi-hotspot, then run a webserver on it, and browse it from another phone connected to the hotspot.

我的手机没有根,但我有 termux ,它有许多unix实用程序。我不想安装额外的应用程序。 (但很高兴写一个!)

My phone isn't rooted, but I have termux, which has many unix utilities. I don't want to install an extra app. (But happy to write one!)

我可以在 http:// localhost 上查看python的简单网络服务器主持人),但不在另一部手机上。我尝试使用主机手机的面向公众的IP(使用whatsmyip类型的网页检查它),但没有用。
有人说移动ISP通过映射不同的内部和外部IP来阻止这种情况......但是在这里,它不是通过ISP,只是热点......

I can view python's simple webserver on http://localhost (on the host), but not on the other phone. I tried using the public-facing IP of the host phone (checking it using whatsmyip-type webpages), but didn't work. Someone said that mobile ISPs prevent this, by mapping different internal and external IPs... but here, it's not going through the ISP, just the hotspot...

我还尝试了来自 ifconfig 的I​​P地址以及android中的wifi控件, netcat <工作 - 但只有连接到热点(而不是主机)的客户端电话的IP。

I also tried IP addresses from ifconfig and from the wifi controls within android, which does work for netcat - but only the IP of the client phone connected to the hotspot (not the host).

netcat 在连接到热点的电话上并收听,然后热点电话上的 netcat 连接到它。 (ierole swap:hotspot客户端是netcat服务器)。奇怪的是,热点手机似乎没有一个IP(至少,到目前为止,我还没有发现过这个IP)。但它必须有一个,绝对不能, netcat 连接......?

That is, netcat is on the phone connected to the hotspot and listens, then netcat on hotspot phone connects to it. (i.e.role swap: hotspot client is netcat server). Weirdly, the hotspot phone doesn't seem to have an IP (at least, not one I've been able to discover, so far). But it must have one, mustn't it, for netcat to connect...?

无论如何,我想要热点主机上的网络服务器,所以我需要它的IP连接到它...有没有办法得到它?

Anyway, I want the webserver on the hotspot host, so I need its IP to connect to it... is there a way to get it?

这已经困扰了我多年。
非常感谢您的帮助!

This has been bugging me for ages. Many thanks for any help!

编辑这个问题说它(差不多)总是192.168.43.1。我现在不能尝试;我会更新。

EDIT the answers to this question says it's (almost) always 192.168.43.1. I can't try it right now; will update when I have.

更新

1. 192.168.43.1 作品

2. py http.server 适用于常规文件(例如txt,pdf),但视频文件似乎需要一些它缺乏流媒体协议。我发现 lighttpd 有这个(在 termux 中使用 apt install lighttpd )。但它需要配置(并且没有eg / default)。我用过:

UPDATE
1. 192.168.43.1 works
2. py http.server works fine for regular files (e.g. txt, pdf), but video files seem to require some streaming protocol it lacks. I found lighttpd had this (available within termux using apt install lighttpd). But it needs config (and no eg/default). I used:

$ cat > lighttp.conf
dir-listing.activate = "enable"
server.port = 8000
server.document-root = "MY PATH HERE"
$ lighttpd -D -f lighttpd.conf

目录列表使它更容易使用,但显然没有配置安全性,所以想要小心你提供的东西。

3. Android(我的5.1,无论如何)需要飞机模式关闭才能使它成为一个wifi热点 - 这对于互联网访问是有意义的...但是在这里,我只希望客户端可以访问主机,而不是整个互联网都可以访问它。因此,我发现您可以关闭数据访问以防止这种情况,并且热点仍然有效。 (肯定有一种方法可以通过编程方式在飞机模式下设置热点......)

The dir listing makes it much easier to use, but obviously no security configured here, so want to be careful what you make available.
3. Android (my 5.1, anyway) needs airplane mode off before you can make it a wifi hotspot - which makes sense for internet access... but here, I want only the client to have access to the host, not have it accessible to the whole internet. So I found you can turn off data-access to prevent that, and the hotspot still works. (There's surely a way to have a hotspot in airplane mode programmatically...)

你有它!打电话为媒体服务器。

There you have it! Phone as media server.

推荐答案

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;
}

这会对你有所帮助。

这篇关于android热点上的webserver - 它的IP是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆