FRP内网穿透获取真实IP
时间: 2024-01-20 22:14:22 浏览: 353
FRP是一款高性能的内网穿透工具,可以将内网服务暴露到公网上,从而实现公网访问内网服务的功能。在FRP中,要想获取访客的真实IP,需要在frpc客户端中进行配置。具体步骤如下:
1.在frpc客户端的配置文件中,添加以下配置:
```ini
[common]
server_addr = x.x.x.x # frps服务器的IP地址
server_port = 7000 # frps服务器的端口号
[web]
type = http
local_port = 80 # 内网服务的端口号
custom_domains = example.com # 自定义域名
# 添加以下配置
use_x_forwarded_for = true
```
2.在内网服务中,获取访客的真实IP。在Python中,可以通过以下代码获取:
```python
from flask import request
@app.route('/')
def index():
ip = request.headers.get('X-Forwarded-For', request.remote_addr)
return 'Your IP address is {}'.format(ip)
```
其中,`X-Forwarded-For`是一个HTTP请求头,用于记录客户端的真实IP地址。在FRP中,设置`use_x_forwarded_for = true`后,FRP会在HTTP请求头中添加`X-Forwarded-For`字段,记录访客的真实IP地址。
相关问题
FRP内网穿透获取真实IP,IIS搭建
FRP内网穿透获取真实IP的方法如下:
1.在nginx配置文件中添加以下内容:
```
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://your_internal_server;
}
```
2.在frpc.ini文件中添加以下内容:
```
[common]
server_addr = x.x.x.x
server_port = 7000
token = 12345678
[web]
type = http
local_port = 80
custom_domains = example.com
```
其中,x.x.x.x是你的frps服务器的IP地址,token是你在frps服务器上设置的token,example.com是你要映射的域名。
3.启动frpc客户端,执行以下命令:
```
./frpc -c frpc.ini
```
4.在浏览器中输入example.com,即可访问你的内网服务器,并且nginx会将真实IP地址传递给内网服务器。
关于IIS搭建,你可以参考以下步骤:
1.在IIS中创建一个网站,将网站的物理路径指向你的应用程序。
2.在防火墙中打开对应的端口。
3.在frpc.ini文件中添加以下内容:
```
[common]
server_addr = x.x.x.x
server_port = 7000
token = 12345678
[web]
type = http
local_port = 80
custom_domains = example.com
```
其中,x.x.x.x是你的frps服务器的IP地址,token是你在frps服务器上设置的token,example.com是你要映射的域名。
4.启动frpc客户端,执行以下命令:
```
./frpc -c frpc.ini
```
5.在浏览器中输入example.com,即可访问你的内网服务器。
IIS环境FRPC内网穿透获取真实IP
根据提供的引用内容,我们可以得知FRP是一种内网穿透工具,可以将内网的服务暴露到公网上。而在FRP内网穿透获取的IP地址通常是127.0.0.1,如果想要获取当前请求用户的真实IP,可以在IIS环境中通过以下步骤实现:
1. 在IIS中添加一个自定义的HTTP头,例如X-Real-IP,用于存储真实IP地址。
2. 在IIS的反向代理服务器中,将请求头中的X-Real-IP转发到后端服务器。
3. 在后端服务器中,获取请求头中的X-Real-IP即可获取到真实IP地址。
以下是具体的代码示例:
1. 在IIS中添加自定义HTTP头X-Real-IP
```powershell
# 打开PowerShell命令行窗口
# 进入IIS管理模块
Import-Module WebAdministration
# 添加自定义HTTP头
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/proxy" -name "customHeaders" -value @{name='X-Real-IP';value=''} -AtIndex 0
```
2. 在反向代理服务器中转发X-Real-IP
```nginx
# 在nginx配置文件中添加以下内容
location / {
proxy_pass http://backend;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
```
3. 在后端服务器中获取X-Real-IP
```python
# 在Python代码中获取X-Real-IP
real_ip = request.headers.get('X-Real-IP')
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)