Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,894 members, 7,817,628 topics. Date: Saturday, 04 May 2024 at 03:53 PM

Please Someone Should Read This Code... - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Someone Should Read This Code... (445 Views)

I Am Bored, I Just Tried This Code / Eyeopener: Aspiring Nigerian Game/App Developers Should Read This / Java Programmers ,I Need Help Fixing This Code. (2) (3) (4)

(1) (Reply) (Go Down)

Please Someone Should Read This Code... by Nick08130(m): 6:47am On Nov 04, 2022
```python
#!/usr/bin/env python3

# Python SSH Checker
# Fix indent =G:wq
import argparse
import socket
import paramiko
import sys
import os

class SystemScanner:

def __init__(self, target, port, service):
#Globals?
self.target = target
self.port = port
self.service = service

def test_ssh(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((self.target, self.port))
print("SSH Open"wink
except Exception as err:
#Conn failed
print(f"Connection failed on "wink
finally:
sock.close()

def ssh_auth(self):
test = paramiko.Transport((self.target, self.port))
try:
test.connect()
except paramiko.ssh_exception.SSHException as err:
print(f"SSH Connection failed:", self.host, self.port, "because ", str(err))
test.close()
exit(1)
try:
test.auth_none('')
except paramiko.BadAuthenticationType as err:
print(err.allowed_types)
finally:
test.close()

def ssh_login(self):
print(f"Checking {self.service} logins..."wink
try:
print("Dropping into shell"wink
command = "journalctl --system --follow | grep -i ssh"
'''TODO
1) Parse output and find get the info cleaner
2) Add Services [http, ftp, smb]
3) clean exit
4) Counters for successfull/failed logins
'''

os.system(command)
except KeyboardInterrupt as kd:
exit(1)
finally:
print("\n\n\r\nEND"wink


if __name__ == '__main__':
parser = argparse.ArgumentParser(prog="sysmon.py"wink
parser.add_argument('--port', '-p', help="Enter Port Number", type=int, default=22)
parser.add_argument('--target', '-t', help='Hostname or IP', default="127.0.0.1"wink
parser.add_argument('--service', '-s', help="Show Service logins", default="ssh"wink
args = parser.parse_args()

scanner = SystemScanner(args.target, args.port, args.service)
if scanner.test_ssh():
scanner.ssh_auth()
if args.service:
scanner.ssh_login()
```
Re: Please Someone Should Read This Code... by bedfordng(m): 11:38am On Nov 04, 2022
The code is self explanatory. Code is simply used for making SSH connection. So when running the script you have to add the arguments such as target, port , service etc along with the script else it won't work.

Are you the one that created it.
Re: Please Someone Should Read This Code... by Skodrran(m): 3:11pm On Nov 04, 2022
Socket programming undecided

(1) (Reply)

Learning HTML And CSS For Beginners / Seo Optimization (I Need Help) / Can One Developer Build A Function Social App By Himself

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.