[GH-ISSUE #3172] [Feature Request] frp配置的时候是否支持srv解析的域名 #2544

Closed
opened 2026-05-05 13:38:17 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @Gu-f on GitHub (Nov 17, 2022).
Original GitHub issue: https://github.com/fatedier/frp/issues/3172

Describe the feature request

配置frps.ini的时候需要指定ip和端口,但是在某些场景下,ip和端口用了srv进行dns解析,导致没有端口,只有个域名,这种情况下支持吗?如果当前不支持,是否考虑以后支持这种配置

Describe alternatives you've considered

No response

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @Gu-f on GitHub (Nov 17, 2022). Original GitHub issue: https://github.com/fatedier/frp/issues/3172 ### Describe the feature request 配置frps.ini的时候需要指定ip和端口,但是在某些场景下,ip和端口用了srv进行dns解析,导致没有端口,只有个域名,这种情况下支持吗?如果当前不支持,是否考虑以后支持这种配置 ### Describe alternatives you've considered _No response_ ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [X] Extensions - [ ] Others
gitea-mirror 2026-05-05 13:38:17 -06:00
Author
Owner

@fatedier commented on GitHub (Nov 18, 2022):

没有计划支持。

<!-- gh-comment-id:1319480690 --> @fatedier commented on GitHub (Nov 18, 2022): 没有计划支持。
Author
Owner

@github-actions[bot] commented on GitHub (Dec 19, 2022):

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.

<!-- gh-comment-id:1356927202 --> @github-actions[bot] commented on GitHub (Dec 19, 2022): Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.
Author
Owner

@wukan1986 commented on GitHub (Dec 13, 2025):

# pip install dnspython
import dns.rdatatype
import dns.rdtypes.IN.SRV
import dns.resolver


def query_srv_record(service, protocol, domain):
    """
    查询SRV记录
    格式: _service._protocol.domain
    例如: _sip._tcp.example.com
    """
    srv_domain = f"_{service}._{protocol}.{domain}"

    try:
        resolver = dns.resolver.Resolver()

        # 设置DNS服务器(可选)
        # resolver.nameservers = ['8.8.8.8']

        # 查询SRV记录
        answer = resolver.resolve(srv_domain, 'SRV')

        results = []
        for rdata in answer:
            # SRV记录包含:优先级、权重、端口、目标主机
            srv_info = {
                'priority': rdata.priority,
                'weight': rdata.weight,
                'port': rdata.port,
                'target': rdata.target.to_text().rstrip('.')
            }
            results.append(srv_info)

        # 按优先级和权重排序
        results.sort(key=lambda x: (x['priority'], -x['weight']))
        return results

    except dns.resolver.NoAnswer:
        print(f"没有找到SRV记录: {srv_domain}")
        return []
    except dns.resolver.NXDOMAIN:
        print(f"域名不存在: {srv_domain}")
        return []
    except Exception as e:
        print(f"查询失败: {e}")
        return []


# 使用示例
srv_records = query_srv_record('frp', 'tcp', 'frp.example.com')
for record in srv_records:
    print(f"目标: {record['target']}:{record['port']} (优先级: {record['priority']}, 权重: {record['weight']})")

toml = """
serverAddr = "{target}"
serverPort = {port}
auth.token = "frp.example.com"

[[proxies]]
name = "test"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 7001

"""

toml = toml.format(target=srv_records[0]['target'], port=srv_records[0]['port'])
print(toml)

with open("frpc.toml", 'w', encoding='utf-8') as f:
    f.write(toml)

@fatedier 您好!

我自己实现了一个功能,提前写入toml文件,但感觉还是能支持SRV更好,比如在serverAddr和serverPort之外再提供一个serverSrv。

用这个能解决没有公网IPv4,但还需要提供frps服务的情况

<!-- gh-comment-id:3648830168 --> @wukan1986 commented on GitHub (Dec 13, 2025): ```python # pip install dnspython import dns.rdatatype import dns.rdtypes.IN.SRV import dns.resolver def query_srv_record(service, protocol, domain): """ 查询SRV记录 格式: _service._protocol.domain 例如: _sip._tcp.example.com """ srv_domain = f"_{service}._{protocol}.{domain}" try: resolver = dns.resolver.Resolver() # 设置DNS服务器(可选) # resolver.nameservers = ['8.8.8.8'] # 查询SRV记录 answer = resolver.resolve(srv_domain, 'SRV') results = [] for rdata in answer: # SRV记录包含:优先级、权重、端口、目标主机 srv_info = { 'priority': rdata.priority, 'weight': rdata.weight, 'port': rdata.port, 'target': rdata.target.to_text().rstrip('.') } results.append(srv_info) # 按优先级和权重排序 results.sort(key=lambda x: (x['priority'], -x['weight'])) return results except dns.resolver.NoAnswer: print(f"没有找到SRV记录: {srv_domain}") return [] except dns.resolver.NXDOMAIN: print(f"域名不存在: {srv_domain}") return [] except Exception as e: print(f"查询失败: {e}") return [] # 使用示例 srv_records = query_srv_record('frp', 'tcp', 'frp.example.com') for record in srv_records: print(f"目标: {record['target']}:{record['port']} (优先级: {record['priority']}, 权重: {record['weight']})") toml = """ serverAddr = "{target}" serverPort = {port} auth.token = "frp.example.com" [[proxies]] name = "test" type = "tcp" localIP = "127.0.0.1" localPort = 8080 remotePort = 7001 """ toml = toml.format(target=srv_records[0]['target'], port=srv_records[0]['port']) print(toml) with open("frpc.toml", 'w', encoding='utf-8') as f: f.write(toml) ``` @fatedier 您好! 我自己实现了一个功能,提前写入toml文件,但感觉还是能支持SRV更好,比如在serverAddr和serverPort之外再提供一个serverSrv。 用这个能解决没有公网IPv4,但还需要提供frps服务的情况
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2544
No description provided.