ISP detection does not work for LAN clients behind NAT

未关闭
#862 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
php
领域
api, backend

调研方向

Start with backend/getIP.php, especially getLocalOrPrivateIpInfo($ip) and the existing IPinfo request used by /backend/getIP.php?isp=true. Trace how configuration is defined and how the response is formatted before deciding where the opt-in setting belongs. Done means private client IPs remain unchanged while enabled deployments can use the server's public IP for ISP/location data, without changing the default behavior.

由索引模型根据 Issue 内容生成。

描述

Hi Team, I'm running LibreSpeed on a server inside my home network. When I access the speedtest from another device on the same LAN, LibreSpeed correctly detects the client's private IP address, but ISP detection is skipped.

For example, the client is:

192.168.1.23

and the LibreSpeed server is:

192.168.1.10

Calling:

/backend/getIP.php?isp=true

returns:

{
  "processedString": "192.168.1.23 - private IPv4 access",
  "rawIspInfo": ""
}
Why this happens

backend/getIP.php checks for private addresses before trying IPinfo:

$localIpInfo = getLocalOrPrivateIpInfo($ip);

if (is_string($localIpInfo)) {
    echo formatResponse_simple($ip,$localIpInfo);
}

So an address such as 192.168.1.23 is never sent to IPinfo.

That makes sense by itself, since a private IP cannot be geolocated. However, for a typical home network the LibreSpeed server and the client are behind the same NAT gateway and therefore share the same public IP.

The server can already determine its public IP using the existing IPinfo integration:

https://ipinfo.io/json?token=...

So it seems possible to use the server's public IP for ISP/location lookup when the client IP is private.

Possible solution

Would it make sense to add an optional setting for this use case?

For example:

USE_SERVER_PUBLIC_IP_FOR_PRIVATE_CLIENTS=true

When enabled:

  1. Detect the client IP as usual.
  2. If it is a private/local address, don't send that address to IPinfo.
  3. Instead query IPinfo without an IP address so that IPinfo sees the server's public address.
  4. Use the returned ISP/country/location information for the result.
  5. Keep the actual client IP unchanged.

For example, instead of:

192.168.1.23 - private IPv4 access

the result could show something like:

192.168.1.23 - Example ISP, DE
Why should this be optional?

The server and client do not necessarily have to use the same public IP. This could be wrong when LibreSpeed is behind a VPN, proxy, multiple network interfaces, etc.

Therefore I think this should be opt-in rather than changing the current behavior for every private IP.

Environment
  • LibreSpeed Docker image: ghcr.io/librespeed/speedtest:latest
  • Client and server are on the same private LAN
  • Server has Internet access through a NAT router
  • IPinfo API key is configured and working
  • /backend/getIP.php?isp=true works correctly for public IPs
Expected behavior

It would be useful if LibreSpeed could optionally provide ISP/location information for LAN clients behind NAT, while still correctly identifying the actual client IP as private.

Is this something that would be considered?

主要语言
JavaScript
星标
15.3k
派生
2.5k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

librespeed/speedtest 的其他 Issue

查看 librespeed/speedtest 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。