Here is how you can format Scrapy export of your items
For all of these options make sure that your spider actually yields some results in your parse
method.
Here is how you can format Scrapy export of your items
For all of these options make sure that your spider actually yields some results in your parse
method.
The below will return True/False
import socket def test_connection(host="8.8.8.8", port=53, timeout=3): try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True except Exception as ex: #print ex.message return False destination_host = "mymachine.company" destination_port = 9997 timeout = 2 test_result = test_connection(destination_host, destination_port, timeout)
Or you can use this version to return the Exception in case connection has failed
import socket def test_connection(host="8.8.8.8", port=53, timeout=3): try: socket.setdefaulttimeout(timeout) socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) return True, None except Exception as ex: #print ex.message return False, ex.message destination_host = "mymachine.company" destination_port = 9997 timeout = 2 test_result, ex = test_connection(destination_host, destination_port, timeout)
Here is how to use Python – to Get local machine IP
import socket def get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even have to be reachable s.connect(('10.255.255.255', 1)) IP = s.getsockname()[0] except: IP = '127.0.0.1' finally: s.close() return IP