验证IPTV流(UDP)的Python脚本

3 投票
1 回答
5520 浏览
提问于 2025-04-16 09:18

我的光纤互联网服务提供商支持通过UDP来播放IPTV。不过,他们并没有在任何地方列出频道。

我大部分频道都是自己找出来的,但我想要一个脚本,能够检查某个频道是否活跃或可用。

有没有什么主意可以用Python来实现这个?

1 个回答

1

我觉得这个Python代码应该像下面这样。注意,不要在Python的IDLE环境中运行它,因为ipRange()会让它卡住。

def ipRange(start_ip, end_ip):
  start = list(map(int, start_ip.split(".")))
  end = list(map(int, end_ip.split(".")))
  temp = start
  ip_range = []

  ip_range.append(start_ip)
  while temp != end:
    start[3] += 1
    for i in (3, 2, 1):
      if temp[i] == 256:
        temp[i] = 0
        temp[i-1] += 1
    ip_range.append(".".join(map(str, temp)))    
  return ip_range

def IPTVSignalTest(ip):
  # do your test here, return true if IPTV signal, false otherwise
  return TRUE

ip_range = ipRange("192.168.1.0", "192.171.3.25")
save_ip = []
for ip in ip_range:
  if IPTVSignalTest(ip):
    save_ip.append(ip)

撰写回答