Find the first opened localhost port from a given list of ports (e.g. for Tor port checks)
(ports)
| 2889 | return retVal |
| 2890 | |
| 2891 | def findLocalPort(ports): |
| 2892 | """ |
| 2893 | Find the first opened localhost port from a given list of ports (e.g. for Tor port checks) |
| 2894 | """ |
| 2895 | |
| 2896 | retVal = None |
| 2897 | |
| 2898 | for port in ports: |
| 2899 | try: |
| 2900 | try: |
| 2901 | s = socket._orig_socket(socket.AF_INET, socket.SOCK_STREAM) |
| 2902 | except AttributeError: |
| 2903 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 2904 | s.connect((LOCALHOST, port)) |
| 2905 | retVal = port |
| 2906 | break |
| 2907 | except socket.error: |
| 2908 | pass |
| 2909 | finally: |
| 2910 | try: |
| 2911 | s.close() |
| 2912 | except socket.error: |
| 2913 | pass |
| 2914 | |
| 2915 | return retVal |
| 2916 | |
| 2917 | def findMultipartPostBoundary(post): |
| 2918 | """ |
no test coverage detected
searching dependent graphs…