Skip to content

Commit

Permalink
Merge pull request #4 from cdavidb82/dev-dave
Browse files Browse the repository at this point in the history
Merge Updates
  • Loading branch information
cdavidb82 authored Nov 8, 2024
2 parents 09beb41 + 1175e33 commit 1e4e150
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 29 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
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.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,37 @@

This repository contains a collection of Python scripts designed to simplify and automate various tasks for network engineers. The scripts are organized into categories and include documentation for easy use.

### Contents
### Table of Contents

#### Scripts
* [Script 1: Network Device Configuration](#script-1-network-device-configuration)
* [Script 2: Network Monitoring](#script-2-network-monitoring)
* [Script 3: Network Automation](#script-3-network-automation)
* [Script 4: Network Security](#script-4-network-security)
* [Script 5: Network Troubleshooting](#script-5-network-troubleshooting)

#### Additional Resources
* [Contributing Guidelines](#contributing-guidelines)
* [Feedback and Support](#feedback-and-support)
* [FAQ](#faq)
* [Change Log](#change-log)

### Getting Started

To get started with the scripts, follow these steps:

1. Clone the repository using `git clone https://github.com/username/PyNetworkScripts.git`
2. Install the required dependencies using `pip install -r requirements.txt`
3. Read the documentation for each script to understand its usage and configuration

### Contributing

Contributions and feedback are welcome. If you have any suggestions or ideas for new scripts, please don't hesitate to reach out. You can contribute by:

* Submitting a pull request with your changes
* Opening an issue to report a bug or request a feature
* Contacting us through email or social media

### Thank you

Contributions and feedback are welcome. If you have any suggestions or ideas for new scripts, please don't hesitate to reach out.
We appreciate your contributions and feedback. If you have any questions or need help, please don't hesitate to reach out.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ scp==0.15.0
setuptools==75.3.0
six==1.16.0
textfsm==1.1.3
WMI==1.4.9
27 changes: 17 additions & 10 deletions server_processes.py
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)
16 changes: 9 additions & 7 deletions show_process.py
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)
35 changes: 25 additions & 10 deletions sniffingPackets.py
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()

0 comments on commit 1e4e150

Please sign in to comment.