Skip to content

Commit b6582e0

Browse files
alirezaalireza
authored andcommitted
removed spaces and lines
1 parent d436e3c commit b6582e0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

site_health.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#! /usr/bin/env python
2-
"""This script is very useful to just to see get status/infromation about your host and it's certificate"""
2+
"""This script is very useful for when you just to do a health check on a remote server. It does the followings:
3+
- NSLOOKUP
4+
- PING to see if the site is up
5+
- Certificate/SSL/TLS info """
36
from urllib.request import Request, urlopen, ssl, socket
47
from urllib.error import URLError, HTTPError
58
import os,json,hashlib, re
@@ -16,7 +19,6 @@ def __init__(self, base_url, port, tcp):
1619
self.ping_host()
1720
self.obtain_http_info()
1821
self.obtain_cert_info()
19-
2022

2123
def obtain_ip(self):
2224
print("__LOOKUP____________________________________________")
@@ -46,7 +48,6 @@ def ping_host(self):
4648

4749
def obtain_http_info(self):
4850
print("__SSL/TLS INFO____________________________________________")
49-
5051
req = Request(self.url_path)
5152
try:
5253
response = urlopen(req,context=ssl._create_unverified_context())
@@ -61,13 +62,11 @@ def obtain_http_info(self):
6162
print("http code:"+str(response.getcode()) )
6263

6364
def obtain_cert_info(self):
64-
6565
context = ssl.create_default_context()
6666
with socket.create_connection((self.base_url, self.port)) as socket_connection:
6767
with context.wrap_socket(socket_connection, server_hostname=self.base_url) as server_socket:
6868
#uncomment to print everything
6969
#print(json.dumps(server_socket.getpeercert() , indent=2, sort_keys=True))
70-
7170
cert_info = server_socket.getpeercert()
7271
subject = dict(x[0] for x in cert_info['subject'])
7372
issued_to = subject['commonName']
@@ -76,12 +75,8 @@ def obtain_cert_info(self):
7675
valid_from =cert_info['notBefore']
7776
valid_to = cert_info['notAfter']
7877
serial_number =cert_info['serialNumber']
79-
80-
81-
8278
der_cert = server_socket.getpeercert(False)
8379
der_cert_bin = server_socket.getpeercert(True)
84-
8580
pem_cert = ssl.DER_cert_to_PEM_cert(server_socket.getpeercert(True))
8681
# uncomment the below line if you want to see the actual public cert
8782
#print("certificate pub:",pem_cert)
@@ -102,7 +97,6 @@ def obtain_cert_info(self):
10297
server_socket.close()
10398

10499

105-
106100
if __name__ == '__main__':
107101
# DO NOT USE IP
108102

0 commit comments

Comments
 (0)