gpt4 book ai didi

firebase - 如何获取 Firebase 函数的 IP 地址或范围?

转载 作者:行者123 更新时间:2023-12-02 15:33:03 25 4
gpt4 key购买 nike

如果我们想获取项目中Firebase函数的IP地址或范围,该怎么办?因为我们必须提供这个IP范围以获得特定的服务器权限。

最佳答案

使用此代码获取实际的 ip 列表

from dns import resolver
import ipaddress
import re


domain_pattern = re.compile('(([\da-zA-Z_])([_\w-]{,62})\.){,127}(([\da-zA-Z])[_\w-]{,61})?([\da-zA-Z]\.((xn\-\-[a-zA-Z\d]+)|([a-zA-Z\d]{2,})))$', re.IGNORECASE)


def parse_spf(domain):
ips = set()
answers = resolver.query(domain.strip(), "TXT")
for rdata in answers:
splitted = rdata.to_text().split(' ')
for split in splitted:
split = split.strip()

if split.startswith('ip4:') or split.startswith('ip6:'):
split = split.lstrip('ip4:')
split = split.lstrip('ip6:')

try:
ipaddress.ip_address(split)
ips.add(split)
continue
except ValueError:
pass

try:
ipaddress.ip_network(split)
ips.add(split)
continue
except ValueError:
pass

if split.startswith('include:'):
split = split.lstrip('include:')
if domain_pattern.match(split):
ips.update(parse_spf(split))
continue

print("Unrecognized entry", split)

return ips


if __name__ == "__main__":
domain = '_cloud-netblocks.googleusercontent.com'

ips = parse_spf(domain=domain)

for ip in ips:
print(ip)

关于firebase - 如何获取 Firebase 函数的 IP 地址或范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47447734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com