IPTV.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import time
  2. import concurrent.futures
  3. from selenium import webdriver
  4. from selenium.webdriver.chrome.options import Options
  5. import requests
  6. import json
  7. import re
  8. hebei = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iSGViZWki" #河北
  9. beijing = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iYmVpamluZyI%3D" #北京
  10. guangdong = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iZ3Vhbmdkb25nIg%3D%3D" #广东
  11. shanghai = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ic2hhbmdoYWki" #上海
  12. tianjin = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0idGlhbmppbiI%3D" #天津
  13. chongqing = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iY2hvbmdxaW5nIg%3D%3D" #重庆
  14. shanxi = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ic2hhbnhpIg%3D%3D" #山西
  15. shaanxi = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iU2hhYW54aSI%3D" #陕西
  16. liaoning = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0ibGlhb25pbmci" #辽宁
  17. jiangsu = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iamlhbmdzdSI%3D" #江苏
  18. zhejiang = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iemhlamlhbmci" #浙江
  19. anhui = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5a6J5b69Ig%3D%3D" #安徽
  20. fujian = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0iRnVqaWFuIg%3D%3D" #福建
  21. jiangxi = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rGf6KW%2FIg%3D%3D" #江西
  22. shandong = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5bGx5LicIg%3D%3D" #山东
  23. henan = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rKz5Y2XIg%3D%3D" #河南
  24. hubei = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rmW5YyXIg%3D%3D" #湖北
  25. hunan = "https://fofa.info/result?qbase64=ImlwdHYvbGl2ZS96aF9jbi5qcyIgJiYgY291bnRyeT0iQ04iICYmIHJlZ2lvbj0i5rmW5Y2XIg%3D%3D" #湖南
  26. def process_url(url):
  27. # 创建一个Chrome WebDriver实例
  28. chrome_options = Options()
  29. chrome_options.add_argument('--headless')
  30. chrome_options.add_argument('--no-sandbox')
  31. chrome_options.add_argument('--disable-dev-shm-usage')
  32. driver = webdriver.Chrome(options=chrome_options)
  33. # 使用WebDriver访问网页
  34. driver.get(url) # 将网址替换为你要访问的网页地址
  35. time.sleep(10)
  36. # 获取网页内容
  37. page_content = driver.page_source
  38. # 关闭WebDriver
  39. driver.quit()
  40. # 查找所有符合指定格式的网址
  41. pattern = r"http://\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+" # 设置匹配的格式,如http://8.8.8.8:8888
  42. urls_all = re.findall(pattern, page_content)
  43. #urls = list(set(urls_all)) # 去重得到唯一的URL列表
  44. urls = set(urls_all) # 去重得到唯一的URL列表
  45. x_urls = []
  46. for url in urls: # 对urls进行处理,ip第四位修改为1,并去重
  47. url = url.strip()
  48. ip_start_index = url.find("//") + 2
  49. ip_end_index = url.find(":", ip_start_index)
  50. ip_dot_start = url.find(".") + 1
  51. ip_dot_second = url.find(".", ip_dot_start) + 1
  52. ip_dot_three = url.find(".", ip_dot_second) + 1
  53. base_url = url[:ip_start_index] # http:// or https://
  54. ip_address = url[ip_start_index:ip_dot_three]
  55. port = url[ip_end_index:]
  56. ip_end = "1"
  57. modified_ip = f"{ip_address}{ip_end}"
  58. x_url = f"{base_url}{modified_ip}{port}"
  59. x_urls.append(x_url)
  60. urls = set(x_urls) # 去重得到唯一的URL列表
  61. valid_urls = []
  62. # 多线程获取可用url
  63. with concurrent.futures.ThreadPoolExecutor(max_workers = 100) as executor:
  64. futures = []
  65. for url in urls:
  66. url = url.strip()
  67. modified_urls = modify_urls(url)
  68. for modified_url in modified_urls:
  69. futures.append(executor.submit(is_url_accessible, modified_url))
  70. for future in concurrent.futures.as_completed(futures):
  71. result = future.result()
  72. if result:
  73. valid_urls.append(result)
  74. for url in valid_urls:
  75. print(url)
  76. # 遍历网址列表,获取JSON文件并解析
  77. results = []
  78. for url in valid_urls:
  79. try:
  80. # 发送GET请求获取JSON文件,设置超时时间为0.5秒
  81. ip_start_index = url.find("//") + 2
  82. ip_dot_start = url.find(".") + 1
  83. ip_index_second = url.find("/", ip_dot_start)
  84. base_url = url[:ip_start_index] # http:// or https://
  85. ip_address = url[ip_start_index:ip_index_second]
  86. url_x = f"{base_url}{ip_address}"
  87. json_url = f"{url}"
  88. response = requests.get(json_url, timeout=0.5)
  89. json_data = response.json()
  90. try:
  91. # 解析JSON文件,获取name和url字段
  92. for item in json_data['data']:
  93. if isinstance(item, dict):
  94. name = item.get('name')
  95. urlx = item.get('url')
  96. if 'http' in urlx.lower():
  97. urld = f"{urlx}"
  98. else:
  99. urld = f"{url_x}{urlx}"
  100. if name and urlx:
  101. # 删除特定文字
  102. name = name.replace("中央", "CCTV")
  103. name = name.replace("高清", "")
  104. name = name.replace("HD", "")
  105. name = name.replace("标清", "")
  106. name = name.replace("频道", "")
  107. name = name.replace("-", "")
  108. name = name.replace(" ", "")
  109. name = name.replace("PLUS", "+")
  110. name = name.replace("+", "+")
  111. name = name.replace("(", "")
  112. name = name.replace(")", "")
  113. name = name.replace("CCTV1综合", "CCTV1")
  114. name = name.replace("CCTV2财经", "CCTV2")
  115. name = name.replace("CCTV3综艺", "CCTV3")
  116. name = name.replace("CCTV4国际", "CCTV4")
  117. name = name.replace("CCTV4中文国际", "CCTV4")
  118. name = name.replace("CCTV5体育", "CCTV5")
  119. name = name.replace("CCTV6电影", "CCTV6")
  120. name = name.replace("CCTV7军事", "CCTV7")
  121. name = name.replace("CCTV7军农", "CCTV7")
  122. name = name.replace("CCTV7国防军事", "CCTV7")
  123. name = name.replace("CCTV8电视剧", "CCTV8")
  124. name = name.replace("CCTV9记录", "CCTV9")
  125. name = name.replace("CCTV9纪录", "CCTV9")
  126. name = name.replace("CCTV10科教", "CCTV10")
  127. name = name.replace("CCTV11戏曲", "CCTV11")
  128. name = name.replace("CCTV12社会与法", "CCTV12")
  129. name = name.replace("CCTV13新闻", "CCTV13")
  130. name = name.replace("CCTV新闻", "CCTV13")
  131. name = name.replace("CCTV14少儿", "CCTV14")
  132. name = name.replace("CCTV15音乐", "CCTV15")
  133. name = name.replace("CCTV16奥林匹克", "CCTV16")
  134. name = name.replace("CCTV17农业农村", "CCTV17")
  135. name = name.replace("CCTV5+体育赛视", "CCTV5+")
  136. name = name.replace("CCTV5+体育赛事", "CCTV5+")
  137. if 'udp' in urld or 'rtp' in urld:
  138. pass
  139. else:
  140. results.append(f"{name},{urld}")
  141. except:
  142. continue
  143. except:
  144. continue
  145. return results
  146. def save_results(results, filename):
  147. # 将结果保存到文本文件
  148. with open(filename, "w", encoding="utf-8") as file:
  149. for result in results:
  150. file.write(result + "\n")
  151. print(result)
  152. def modify_urls(url):
  153. modified_urls = []
  154. ip_start_index = url.find("//") + 2
  155. ip_end_index = url.find(":", ip_start_index)
  156. base_url = url[:ip_start_index] # http:// or https://
  157. ip_address = url[ip_start_index:ip_end_index]
  158. port = url[ip_end_index:]
  159. ip_end = "/iptv/live/1000.json?key=txiptv"
  160. for i in range(1, 256):
  161. modified_ip = f"{ip_address[:-1]}{i}"
  162. modified_url = f"{base_url}{modified_ip}{port}{ip_end}"
  163. modified_urls.append(modified_url)
  164. return modified_urls
  165. def is_url_accessible(url):
  166. try:
  167. response = requests.get(url, timeout=0.5)
  168. if response.status_code == 200:
  169. return url
  170. except requests.exceptions.RequestException:
  171. pass
  172. return None
  173. # 处理第1个URL
  174. results_hebei = process_url(hebei)
  175. save_results(results_hebei, "hebei.txt")
  176. # 处理第2个URL
  177. results_beijing = process_url(beijing)
  178. save_results(results_beijing, "beijing.txt")
  179. # 处理第3个URL
  180. results_guangdong = process_url(guangdong)
  181. save_results(results_guangdong, "guangdong.txt")
  182. # 处理第4个URL
  183. results_shanghai = process_url(shanghai)
  184. save_results(results_shanghai, "shanghai.txt")
  185. # 处理第5个URL
  186. results_tianjin = process_url(tianjin)
  187. save_results(results_tianjin, "tianjin.txt")
  188. # 处理第6个URL
  189. results_chongqing = process_url(chongqing)
  190. save_results(results_chongqing, "chongqing.txt")
  191. # 处理第7个URL
  192. results_shanxi = process_url(shanxi)
  193. save_results(results_shanxi, "shanxi.txt")
  194. # 处理第8个URL
  195. results_shaanxi = process_url(shaanxi)
  196. save_results(results_shaanxi, "shaanxi.txt")
  197. # 处理第9个URL
  198. results_liaoning = process_url(liaoning)
  199. save_results(results_liaoning, "liaoning.txt")
  200. # 处理第10个URL
  201. results_jiangsu = process_url(jiangsu)
  202. save_results(results_jiangsu, "jiangsu.txt")
  203. # 处理第11个URL
  204. results_zhejiang = process_url(zhejiang)
  205. save_results(results_zhejiang, "zhejiang.txt")
  206. # 处理第12个URL
  207. results_anhui = process_url(anhui)
  208. save_results(results_anhui, "anhui.txt")
  209. # 处理第13个URL
  210. results_fujian = process_url(fujian)
  211. save_results(results_fujian, "fujian.txt")
  212. # 处理第14个URL
  213. results_jiangxi = process_url(jiangxi)
  214. save_results(results_jiangxi, "jiangxi.txt")
  215. # 处理第15个URL
  216. results_shandong = process_url(shandong)
  217. save_results(results_shandong, "shandong.txt")
  218. # 处理第16个URL
  219. results_henan = process_url(henan)
  220. save_results(results_henan, "henan.txt")
  221. # 处理第17个URL
  222. results_hubei = process_url(hubei)
  223. save_results(results_hubei, "hubei.txt")
  224. # 处理第18个URL
  225. results_hunan = process_url(hunan)
  226. save_results(results_hunan, "hunan.txt")
  227. # 合并文件内容
  228. file_contents = []
  229. file_paths = ["hebei.txt", "beijing.txt", "guangdong.txt", "shanghai.txt", "tianjin.txt", "chongqing.txt", "shanxi.txt", "shaanxi.txt", "liaoning.txt", "jiangsu.txt", "zhejiang.txt", "anhui.txt", "fujian.txt", "jiangxi.txt", "shandong.txt", "henan.txt", "hubei.txt", "hunan.txt"] # 替换为实际的文件路径列表
  230. for file_path in file_paths:
  231. with open(file_path, 'r', encoding="utf-8") as file:
  232. content = file.read()
  233. file_contents.append(content)
  234. # 写入合并后的文件
  235. with open("IPTV.txt", "w", encoding="utf-8") as output:
  236. output.write('\n'.join(file_contents))