From a474f5f5efb960989749d449c21212b4e36fec24 Mon Sep 17 00:00:00 2001 From: x p k Date: Wed, 6 Mar 2024 09:51:53 +0800 Subject: [PATCH] UPD: various clean up --- py/__pycache__/prettytable.cpython-310.pyc | Bin 611 -> 0 bytes py/__pycache__/terminaltables.cpython-310.pyc | Bin 377 -> 0 bytes py/dates-test.py | 5 +++ py/ldap-monitor.py | 33 ++++++++++++++++++ py/ldaps.py | 13 +++++++ py/port-test.py | 15 ++++++++ test/test.txt | 2 -- 7 files changed, 66 insertions(+), 2 deletions(-) delete mode 100644 py/__pycache__/prettytable.cpython-310.pyc delete mode 100644 py/__pycache__/terminaltables.cpython-310.pyc create mode 100755 py/dates-test.py create mode 100644 py/ldap-monitor.py create mode 100644 py/ldaps.py create mode 100755 py/port-test.py delete mode 100644 test/test.txt diff --git a/py/__pycache__/prettytable.cpython-310.pyc b/py/__pycache__/prettytable.cpython-310.pyc deleted file mode 100644 index 3b1f96bea164c14273813dca810c75c4e19eb7ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 611 zcmY+CziSjh7>2*u+uhvlC59-PMkH9dirKH0@mdmE} ztkfpyk}3uf1pfg`!Ai83X|1jo3vK-7ydwK9`@zGr`|j|u`NBc~nD?je;?D%&r-k!z z5qfx+uW&G6L_$h-2mwyUu;V1aoHN3mVT(JbE>i1^ytVc}xef9f0X5?{a zjNL5QhOj%q^FT;Ucc8e|^%ELP9=Zpe4Wa9mjHcYUeZ{E>26<6Qszsh1EcUakqH^Ui z71=J8GIUM5&$y(5ak1zDi1OnSB(@p8yy#iIu0$ErjEkjZ)N4<#LUMA9nH*Z}Z&Ec9 z*`&Z1#O4nI$@g!VuP0OaAdjiiV#^l)y55=+EKYPtb|K`%#%-?-!y*J=WKNrDebdNqQ&)luoy@#Q1y2W%M+Ac&ncrZiuO?Ovt z$%b|>rJ19Q4OKoeUZF&$KY+T3k4?v)8&O(Eqg?Gp`^DbvMCgcBX;DT+9i8i4Eo#%g Zm*%XJ{679RP+q|?4?YRVg~l~c{sCtFrosRK diff --git a/py/__pycache__/terminaltables.cpython-310.pyc b/py/__pycache__/terminaltables.cpython-310.pyc deleted file mode 100644 index 91f0ecd926f598150dff4070ef01fa0c53b3c92d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 377 zcmY+8zfQw25XODZAJWh=@C2+80xMxf6>Ll_Wy*rmo)wwKN#rCdMM4Zb4X@;tiIEK< z1}>?J$esN8e)`ULu4c24QM`OUFTd!1@8N%V1XpyLISDd^f@w$r7;d? diff --git a/py/dates-test.py b/py/dates-test.py new file mode 100755 index 0000000..07e1648 --- /dev/null +++ b/py/dates-test.py @@ -0,0 +1,5 @@ +#!/usr/bin/python3 + +from datetime import datetime +# print (str(datetime.now().year) + "-" + str(datetime.now().month-1)) +print (datetime.now().replace(month=datetime.now().month-1).strftime('%Y-%m')) diff --git a/py/ldap-monitor.py b/py/ldap-monitor.py new file mode 100644 index 0000000..fe9e104 --- /dev/null +++ b/py/ldap-monitor.py @@ -0,0 +1,33 @@ +import json +import socket +import boto3 + +def lambda_handler(event, context): + hosts=['10.129.72.63', '10.135.72.66', '10.129.72.64', '10.135.72.67'] + port=636 + timeout_seconds=1 + test_results = 0 + for host in hosts: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(timeout_seconds) + result = sock.connect_ex((host,int(port))) + + if result == 0: + print("Host {}:{} - Up".format(host, port)) + test_results += 1 + else: + print("Host {}:{} - Down".format(host, port)) + sock.close() + + if test_results == 4: + return { + 'message' : 'Successfully connected to all LDAP servers' + } + else: + raise Exception('Not all LDAP servers can be connected!') + + return { + 'statusCode': 200, + 'body': json.dumps("Finished") + } + diff --git a/py/ldaps.py b/py/ldaps.py new file mode 100644 index 0000000..d5a1bb5 --- /dev/null +++ b/py/ldaps.py @@ -0,0 +1,13 @@ +import ldap + +LDAP_SERVER = 'ldap://192.168.86.87' +BASE_DN = 'dc=acme,dc=local' # base dn to search in +LDAP_LOGIN = 'Administrator' +LDAP_PASSWORD = 'qwerty-asdf-1234' +OBJECT_TO_SEARCH = 'userPrincipalName=Administrator@acme.local' +ATTRIBUTES_TO_SEARCH = ['memberOf'] + +connect = ldap.initialize(LDAP_SERVER) +connect.set_option(ldap.OPT_REFERRALS, 0) # to search the object and all its descendants +connect.simple_bind_s(LDAP_LOGIN, LDAP_PASSWORD) +result = connect.search_s(BASE_DN, ldap.SCOPE_SUBTREE, OBJECT_TO_SEARCH, ATTRIBUTES_TO_SEARCH) diff --git a/py/port-test.py b/py/port-test.py new file mode 100755 index 0000000..3c70800 --- /dev/null +++ b/py/port-test.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 +import socket + +hosts=['192.168.86.51', '192.168.86.53'] +port=22 +timeout_seconds=1 +for host in hosts: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(timeout_seconds) + result = sock.connect_ex((host,int(port))) + if result == 0: + print("Host {}:{} - Up".format(host, port)) + else: + print("Host {}:{} - Down".format(host, port)) + sock.close() diff --git a/test/test.txt b/test/test.txt deleted file mode 100644 index 1191247..0000000 --- a/test/test.txt +++ /dev/null @@ -1,2 +0,0 @@ -1 -2