itvall(ZHGXTV).py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import time
  2. import os
  3. import concurrent.futures
  4. from selenium import webdriver
  5. from selenium.webdriver.chrome.options import Options
  6. import requests
  7. import re
  8. ###urls城市根据自己所处地理位置修改
  9. urls = [
  10. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0iY2hhbmdzaGEi", # changsha 长沙
  11. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0iemh1emhvdSI%3D", # zhuzhou 株洲
  12. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0iaGVuZ3lhbmci", # hengyang 衡阳
  13. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0ieXVleWFuZyI%3D", # yueyang 岳阳
  14. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0ieWl5YW5nIg%3D%3D", # yiyang 益阳
  15. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0iemh1emhvdSI%3D", # zhuzhou 株洲
  16. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0iaHVhaWh1YSI%3D", # huaihua 怀化
  17. "https://fofa.info/result?qbase64=IlpIR1hUViIgJiYgY2l0eT0ibG91ZGki", # loudi 娄底
  18. ]
  19. def modify_urls(url):
  20. modified_urls = []
  21. ip_start_index = url.find("//") + 2
  22. ip_end_index = url.find(":", ip_start_index)
  23. base_url = url[:ip_start_index] # http:// or https://
  24. ip_address = url[ip_start_index:ip_end_index]
  25. port = url[ip_end_index:]
  26. ip_end = "/ZHGXTV/Public/json/live_interface.txt"
  27. for i in range(1, 256):
  28. modified_ip = f"{ip_address[:-1]}{i}"
  29. modified_url = f"{base_url}{modified_ip}{port}{ip_end}"
  30. modified_urls.append(modified_url)
  31. return modified_urls
  32. def is_url_accessible(url):
  33. try:
  34. response = requests.get(url, timeout=1)
  35. if response.status_code == 200:
  36. return url
  37. except requests.exceptions.RequestException:
  38. pass
  39. return None
  40. results = []
  41. for url in urls:
  42. try:
  43. # 创建一个Chrome WebDriver实例
  44. chrome_options = Options()
  45. chrome_options.add_argument('--headless')
  46. chrome_options.add_argument('--no-sandbox')
  47. chrome_options.add_argument('--disable-dev-shm-usage')
  48. driver = webdriver.Chrome(options=chrome_options)
  49. # 使用WebDriver访问网页
  50. driver.get(url) # 将网址替换为你要访问的网页地址
  51. time.sleep(10)
  52. # 获取网页内容
  53. page_content = driver.page_source
  54. # 关闭WebDriver
  55. driver.quit()
  56. # 查找所有符合指定格式的网址
  57. pattern = r"http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+" # 设置匹配的格式,如http://8.8.8.8:8888
  58. urls_all = re.findall(pattern, page_content)
  59. # urls = list(set(urls_all)) # 去重得到唯一的URL列表
  60. urls = set(urls_all) # 去重得到唯一的URL列表
  61. x_urls = []
  62. for url in urls: # 对urls进行处理,ip第四位修改为1,并去重
  63. url = url.strip()
  64. ip_start_index = url.find("//") + 2
  65. ip_end_index = url.find(":", ip_start_index)
  66. ip_dot_start = url.find(".") + 1
  67. ip_dot_second = url.find(".", ip_dot_start) + 1
  68. ip_dot_three = url.find(".", ip_dot_second) + 1
  69. base_url = url[:ip_start_index] # http:// or https://
  70. ip_address = url[ip_start_index:ip_dot_three]
  71. port = url[ip_end_index:]
  72. ip_end = "1"
  73. modified_ip = f"{ip_address}{ip_end}"
  74. x_url = f"{base_url}{modified_ip}{port}"
  75. x_urls.append(x_url)
  76. urls = set(x_urls) # 去重得到唯一的URL列表
  77. valid_urls = []
  78. # 多线程获取可用url
  79. with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
  80. futures = []
  81. for url in urls:
  82. url = url.strip()
  83. modified_urls = modify_urls(url)
  84. for modified_url in modified_urls:
  85. futures.append(executor.submit(is_url_accessible, modified_url))
  86. for future in concurrent.futures.as_completed(futures):
  87. result = future.result()
  88. if result:
  89. valid_urls.append(result)
  90. for url in valid_urls:
  91. print(url)
  92. # 遍历网址列表,获取JSON文件并解析
  93. for url in valid_urls:
  94. try:
  95. # 发送GET请求获取JSON文件,设置超时时间为0.5秒
  96. json_url = f"{url}"
  97. response = requests.get(json_url, timeout=1)
  98. json_data = response.content.decode('utf-8')
  99. try:
  100. # 按行分割数据
  101. lines = json_data.split('\n')
  102. for line in lines:
  103. line = line.strip()
  104. if line:
  105. name, channel_url = line.split(',')
  106. urls = channel_url.split('/', 3)
  107. url_data = json_url.split('/', 3)
  108. if len(urls) >= 4:
  109. urld = (f"{urls[0]}//{url_data[2]}/{urls[3]}")
  110. else:
  111. urld = (f"{urls[0]}//{url_data[2]}")
  112. print(f"{name},{urld}")
  113. if name and urld:
  114. # 删除特定文字
  115. name = name.replace("cctv", "CCTV")
  116. name = name.replace("中央", "CCTV")
  117. name = name.replace("央视", "CCTV")
  118. name = name.replace("高清", "")
  119. name = name.replace("超高", "")
  120. name = name.replace("HD", "")
  121. name = name.replace("标清", "")
  122. name = name.replace("频道", "")
  123. name = name.replace("-", "")
  124. name = name.replace(" ", "")
  125. name = name.replace("PLUS", "+")
  126. name = name.replace("+", "+")
  127. name = name.replace("(", "")
  128. name = name.replace(")", "")
  129. name = re.sub(r"CCTV(\d+)台", r"CCTV\1", name)
  130. name = name.replace("CCTV1综合", "CCTV1")
  131. name = name.replace("CCTV2财经", "CCTV2")
  132. name = name.replace("CCTV3综艺", "CCTV3")
  133. name = name.replace("CCTV4国际", "CCTV4")
  134. name = name.replace("CCTV4中文国际", "CCTV4")
  135. name = name.replace("CCTV4欧洲", "CCTV4")
  136. name = name.replace("CCTV5体育", "CCTV5")
  137. name = name.replace("CCTV6电影", "CCTV6")
  138. name = name.replace("CCTV7军事", "CCTV7")
  139. name = name.replace("CCTV7军农", "CCTV7")
  140. name = name.replace("CCTV7农业", "CCTV7")
  141. name = name.replace("CCTV7国防军事", "CCTV7")
  142. name = name.replace("CCTV8电视剧", "CCTV8")
  143. name = name.replace("CCTV9记录", "CCTV9")
  144. name = name.replace("CCTV9纪录", "CCTV9")
  145. name = name.replace("CCTV10科教", "CCTV10")
  146. name = name.replace("CCTV11戏曲", "CCTV11")
  147. name = name.replace("CCTV12社会与法", "CCTV12")
  148. name = name.replace("CCTV13新闻", "CCTV13")
  149. name = name.replace("CCTV新闻", "CCTV13")
  150. name = name.replace("CCTV14少儿", "CCTV14")
  151. name = name.replace("CCTV15音乐", "CCTV15")
  152. name = name.replace("CCTV16奥林匹克", "CCTV16")
  153. name = name.replace("CCTV17农业农村", "CCTV17")
  154. name = name.replace("CCTV17农业", "CCTV17")
  155. name = name.replace("CCTV5+体育赛视", "CCTV5+")
  156. name = name.replace("CCTV5+体育赛事", "CCTV5+")
  157. name = name.replace("CCTV5+体育", "CCTV5+")
  158. results.append(f"{name},{urld}")
  159. except:
  160. continue
  161. except:
  162. continue
  163. except:
  164. continue
  165. results = set(results) # 去重得到唯一的URL列表
  166. results = sorted(results)
  167. with open("itv.txt", 'w', encoding='utf-8') as file:
  168. for result in results:
  169. file.write(result + "\n")
  170. print(result)