-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cdavidb82/dev-dave
Merge Updates
- Loading branch information
Showing
6 changed files
with
118 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Changelog | ||
|
||
## [Unreleased] | ||
### Added | ||
- Added input validation and error handling in `server_processes.py` and `show_process.py`. | ||
- Added a main function to orchestrate program flow in the refactored code. | ||
- Added docstrings to functions for better documentation. | ||
- Included an overview and contents sections in the `README.md`. | ||
- Added a call for contributions in the `README.md`. | ||
|
||
### Changed | ||
- Updated `requirements.txt` to include WMI 1.4.9 and later replaced it with ipaddr 2.2.0. | ||
- Updated `requirements.txt` to include 14 new package dependencies and removed none. | ||
- Refactored functions for getting network adapters and printing adapter IPs. | ||
- Refactored the `ping_network` function to accept `ip_net` as an argument and improved error handling. | ||
- Changed CSV reader to use `DictReader` and added error handling for CSV errors. | ||
- Refactored the `download` function to utilize a try-except block and included the `csv` module. | ||
|
||
### Fixed | ||
- Improved error handling in various functions to ensure robustness. | ||
- Refactored `sniffingPackets.py` to create a raw socket and handle exceptions. | ||
|
||
## [2022-11-27] | ||
### Added | ||
- Added `requirements.txt`. | ||
- Created `README.md`. | ||
- Added `.gitignore` file. | ||
- Added `LICENSE`. | ||
|
||
### Removed | ||
- Removed unnecessary files. | ||
|
||
## [2022-04-18] | ||
### Initial Commit | ||
- Initial commit of the project. | ||
|
||
## [2022-04-16] | ||
### Initial Commits | ||
- Multiple initial commits with project setup and basic structure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ scp==0.15.0 | |
setuptools==75.3.0 | ||
six==1.16.0 | ||
textfsm==1.1.3 | ||
WMI==1.4.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
|
||
import wmi | ||
import getpass | ||
|
||
def get_server_credentials(): | ||
server = input("Enter server name: ") | ||
username = input("Enter username: ") | ||
password = getpass.getpass("Enter password: ") | ||
return server, username, password | ||
|
||
def processes(): | ||
connection = wmi.connect_server(server='server-name', user='username', password=getpass.getpass()) | ||
c = wmi.WMI() | ||
watch_process = c.watch_for("operation") | ||
while True: | ||
new = watch_process() | ||
print(new.Caption) | ||
|
||
def processes(server, username, password): | ||
try: | ||
connection = wmi.connect_server(server=server, user=username, password=password) | ||
c = wmi.WMI() | ||
watch_process = c.watch_for("operation") | ||
while True: | ||
new = watch_process() | ||
print(new.Caption) | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == '__main__': | ||
processes() | ||
server, username, password = get_server_credentials() | ||
processes(server, username, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import wmi | ||
|
||
|
||
def show_process(): | ||
c = wmi.WMI() | ||
for process in c.Win32_Process(name='notepad.exe'): | ||
print(process.ProcessId, process.Name) | ||
|
||
def show_process(process_name): | ||
try: | ||
c = wmi.WMI() | ||
for process in c.Win32_Process(name=process_name): | ||
print(f"Process ID: {process.ProcessId}, Process Name: {process.Name}") | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == '__main__': | ||
show_process() | ||
process_name = 'notepad.exe' | ||
show_process(process_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import socket,os | ||
if os.name == "nt": # for Windows | ||
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) | ||
s.bind("10.10.2.107", 0) # your ip | ||
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) | ||
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) | ||
else: | ||
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x800)) # for *Nix | ||
import socket, os | ||
|
||
while True: | ||
pkt = s.recvfrom(65565) # print output on terminal | ||
def create_raw_socket(): | ||
if os.name == "nt": # for Windows | ||
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) | ||
s.bind("10.10.2.107", 0) # your ip | ||
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) | ||
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) | ||
else: | ||
s = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.ntohs(0x800)) # for *Nix | ||
return s | ||
|
||
def main(): | ||
s = create_raw_socket() | ||
while True: | ||
try: | ||
pkt = s.recvfrom(65565) # print output on terminal | ||
print(pkt) | ||
except KeyboardInterrupt: | ||
print("Exiting...") | ||
break | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == "__main__": | ||
main() |