DjangoNetSphere is a sophisticated smart home automation system that leverages the power of Django, a robust web framework, to seamlessly integrate network automation. This project includes a feature-rich temperature dashboard that monitors real-time environmental conditions and triggers network commands based on temperature thresholds.
- Features
- Getting Started
- File Structure
- Temperature Dashboard Flow
- Network Topology
- License
- Contributors
-
Temperature Dashboard: View real-time temperature, humidity, and pressure data through a simple HTML web interface.
-
Network Integration: Dynamically trigger network commands using Telnet based on temperature conditions.
- Python (3.6 or higher)
- Django
- Telnetlib3 -Check requirements.txt
-
Clone the repository:
git clone https://github.com/yourusername/DjangoNetSphere.git cd DjangoNetSphere
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install dependencies:
Copy code pip install -r requirements.txt
-
Set up Django database:
Copy code python manage.py migrate
-
Run the Django development server:
Copy code python manage.py runserver
-
Access the web interface at http://localhost:8000.
-
Django Settings:
- Configure Django settings in
settings.py
, including database settings.
- Configure Django settings in
-
Telnet Configurations:
- Adjust Telnet configurations in
views.py
. - Update the
execute_telnet_commands
function with your specific commands and network details(Such as the host ip address, username, password..etc).
- Adjust Telnet configurations in
-
data.json:
- Stores real-time environmental data.
-
events/views.py:
- Contains view functions, including Telnet commands and data retrieval logic.
-
events/urls.py:
- Defines URL patterns for the application.
-
events/templates/events/home.html:
- HTML template for the home page.
-
requirements.txt:
- Lists project dependencies.
- Random temperature, humidity, and pressure values are generated periodically.
- For professional uses, you can replace the generating functions with real output values.
- The generated data is stored in
data.json
and saved to the database using Django models (Temperature
,Humidity
,Pressure
).
- The web interface (
home.html
) retrieves real-time data from the database and displays it to the user. - Temperature values above a threshold trigger network commands.
🚨 Important Notice:
It's crucial to note that the IP address 192.168.33.161, referred to as 'HOST,' represents the VLAN 1 interface configured earlier. Don't forget to configure your specific IP address to enable Telnet access to your virtual topology.
🔒 Ensure proper configuration for seamless connectivity!
-
execute_telnet_commands:
- Function in
views.py
responsible for establishing a Telnet connection and executing commands on a network device.
def execute_telnet_commands(host, username, password, commands): try: # Connect to the device tn = telnetlib.Telnet(host) # Read the login prompt tn.read_until(b"Username:") tn.write(username.encode('ascii') + b"\n") # Read the password prompt tn.read_until(b"Password:") tn.write(password.encode('ascii') + b"\n") # Wait for the prompt to make sure the login is successful tn.read_until(b">") # Execute commands for command in commands: tn.write(command.encode('ascii') + b"\n") time.sleep(1) # Add a delay to allow the command to be processed # Close the connection tn.close() print("Commands executed successfully.") except Exception as e: print(f"An error occurred: {str(e)}") # Replace these values with your actual ones host = "192.168.33.161" username = "zac" password = "zac" commands = ["enable", "zac", "conf t", "logging console informational"]
- Function in
This project includes a sample network topology created using EVE-NG, a network emulation platform. The topology is designed for testing connectivity and showcasing the integration of Django with network automation.
The topology has been configured to simulate a small network environment. It includes a MultiLayer Cisco Switch to demonstrate the interaction between the Django web application and network devices. The primary goal is to test connectivity and verify the functionality of network commands triggered by the temperature conditions in the Django application.
Feel free to explore and modify the topology for your specific testing needs.
This project is licensed under the MIT License.
- Fouad HELLAL