需要 Python 3.4+,一个参数用来选择测试搜索服务还是 GAE 服务。测试 GAE 服务的话需要先修改开头的两个变量。从标准输入读取 IP 地址或者 IP 段(形如 192.168.0.0/16)列表,每行一个。可用 IP 输出到标准输出。实时测试结果输出到标准错误。50 线程并发。
checkgoogleip
#!/usr/bin/env python3 import sys from ipaddress import IPv4Network import http.client as client from concurrent.futures import ThreadPoolExecutor import argparse import ssl import socket # 先按自己的情况修改以下几行 APP_ID = 'your_id_here' APP_PATH = '/fetch.py' context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) context.verify_mode = ssl.CERT_REQUIRED context.load_verify_locations('/etc/ssl/certs/ca-certificates.crt') class HTTPSConnection(client.HTTPSConnection): def __init__(self, *args, hostname=None, **kwargs): self._hostname = hostname super().__init__(*args, **kwargs) def connect(self): super(client.HTTPSConnection, self).connect() if self._tunnel_host: server_hostname = self._tunnel_host else: server_hostname = self._hostname or self.host sni_hostname = server_hostname if ssl.HAS_SNI else None self.sock = self._context.wrap_socket(self.sock, server_hostname=sni_hostname) if not self._context.check_hostname and self._check_hostname: try: ssl.match_hostname(self.sock.getpeercert(), server_hostname) except Exception: self.sock.shutdown(socket.SHUT_RDWR) self.sock.close() raise def check_ip_p(ip, func): if func(ip): print(ip, flush=True) def check_for_gae(ip): return _check(APP_ID + '.appspot.com', APP_PATH, ip) def check_for_search(ip): return _check('www.google.com', '/', ip) def _check(host, path, ip): for chance in range(1,-1,-1): try: conn = HTTPSConnection( ip, timeout = 5, context = context, hostname = host, ) conn.request('GET', path, headers = { 'Host': host, }) response = conn.getresponse() if response.status < 400: print('GOOD:', ip, file=sys.stderr) else: raise Exception('HTTP Error %s %s' % ( response.status, response.reason)) return True except KeyboardInterrupt: raise except Exception as e: if isinstance(e, ssl.CertificateError): print('WARN: %s is not Google\'s!' % ip, file=sys.stderr) chance = 0 if chance == 0: print('BAD :', ip, e, file=sys.stderr) return False else: print('RE :', ip, e, file=sys.stderr) def main(): parser = argparse.ArgumentParser(description='Check Google IPs') parser.add_argument('service', choices=['search', 'gae'], help='service to check') args = parser.parse_args() func = globals()['check_for_' + args.service] count = 0 with ThreadPoolExecutor(max_workers=50) as executor: for l in sys.stdin: l = l.strip() if '/' in l: for ip in IPv4Network(l).hosts(): executor.submit(check_ip_p, str(ip), func) count += 1 else: executor.submit(check_ip_p, l, func) count += 1 print('%d IP checked.' % count) if __name__ == '__main__': main()

Python和C 各有優勢,選擇應基於項目需求。 1)Python適合快速開發和數據處理,因其簡潔語法和動態類型。 2)C 適用於高性能和系統編程,因其靜態類型和手動內存管理。

選擇Python還是C 取決於項目需求:1)如果需要快速開發、數據處理和原型設計,選擇Python;2)如果需要高性能、低延遲和接近硬件的控制,選擇C 。

通過每天投入2小時的Python學習,可以有效提升編程技能。 1.學習新知識:閱讀文檔或觀看教程。 2.實踐:編寫代碼和完成練習。 3.複習:鞏固所學內容。 4.項目實踐:應用所學於實際項目中。這樣的結構化學習計劃能幫助你係統掌握Python並實現職業目標。

在兩小時內高效學習Python的方法包括:1.回顧基礎知識,確保熟悉Python的安裝和基本語法;2.理解Python的核心概念,如變量、列表、函數等;3.通過使用示例掌握基本和高級用法;4.學習常見錯誤與調試技巧;5.應用性能優化與最佳實踐,如使用列表推導式和遵循PEP8風格指南。

Python適合初學者和數據科學,C 適用於系統編程和遊戲開發。 1.Python簡潔易用,適用於數據科學和Web開發。 2.C 提供高性能和控制力,適用於遊戲開發和系統編程。選擇應基於項目需求和個人興趣。

Python更適合數據科學和快速開發,C 更適合高性能和系統編程。 1.Python語法簡潔,易於學習,適用於數據處理和科學計算。 2.C 語法複雜,但性能優越,常用於遊戲開發和系統編程。

每天投入兩小時學習Python是可行的。 1.學習新知識:用一小時學習新概念,如列表和字典。 2.實踐和練習:用一小時進行編程練習,如編寫小程序。通過合理規劃和堅持不懈,你可以在短時間內掌握Python的核心概念。

Python更易學且易用,C 則更強大但複雜。 1.Python語法簡潔,適合初學者,動態類型和自動內存管理使其易用,但可能導致運行時錯誤。 2.C 提供低級控制和高級特性,適合高性能應用,但學習門檻高,需手動管理內存和類型安全。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版
SublimeText3 Linux最新版