serviceping.network module

Network port scan functions

class serviceping.network.PingResponse(host=None, port=0, ip=None, responding=False, data_mismatch=False, timeout=False, code=None, state=None, length=0, start=None, end=None, error=False, error_message=None, durations=None, response=None, sequence=0, ssl_version='')[source]

Bases: object

Ping response object

hoststr

Destination host or IP address

portint

Destination port

respondingbool

True if ping response was received

data_mismatchbool

True if the recieved packet did not match the sent packet

timeoutbool

True if ping timed out

startfloat

Time started

endfloat

Time ended

duration: float

The duration of the ping operation

property duration

Get The duration based on the timer, or None no timing has been done

start_timer()[source]
stop_timer()[source]
exception serviceping.network.ScanFailed(*args, **kwargs)[source]

Bases: Exception

The scan operation encountered a failure

serviceping.network.ping(host, port=80, url=None, https=False, timeout=1.0, max_size=65535, sequence=0)[source]

Ping a host

Parameters
  • host (str) – The host or ip address to ping

  • port (int, optional) – The port to ping, default=80

  • url (str, optional) – URL to ping, will do a host/port ping if not provided

  • https (bool, optional) – Connect via ssl, default=False

  • timeout (float, optional) – Number of seconds to wait for a response before timing out, default=1 second

  • max_size (int, optional) – The max size of response that can be retrieved. This should be a power of 2 default=65535.

  • sequence (int, optional) – Sequence number for the ping request

Returns

The ping response object

Return type

PingResponse

serviceping.network.scan(host, port=80, url=None, https=False, timeout=1.0, max_size=65535)[source]

Scan a network port

Parameters
  • host (str) – Host or ip address to scan

  • port (int, optional) – Port to scan, default=80

  • url (str, optional) – URL to perform get request to on the host and port specified

  • https (bool, optional) – Perform ssl connection on the socket, default=False

  • timeout (float) – Timeout for network operations, default=1

Returns

Result dictionary that contains the following keys:

host - The host or IP address that was scanned port - The port number that was scanned state - The state of the port, will be either “open” or “closed” durations - An ordered dictionary with floating point value of the time elapsed for each connection operation

Return type

dict

Raises

ScanFailed - The scan operation failed