#1800 - Synced with dev.

- Added the UC2 network.
- Added a Computer class.
This commit is contained in:
Chris McCarthy
2023-08-31 13:35:56 +01:00
parent 415ee3b3a7
commit 89ad22aceb
3 changed files with 221 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
from ipaddress import IPv4Address
from primaite.simulator.network.hardware.base import Node, NIC
class Computer(Node):
"""
A basic computer class.
Example:
>>> pc_a = Computer(
hostname="pc_a",
ip_address="192.168.1.10",
subnet_mask="255.255.255.0",
default_gateway="192.168.1.1"
)
>>> pc_a.power_on()
Instances of computer come 'pre-packaged' with the following:
* Core Functionality:
* ARP.
* ICMP.
* Packet Capture.
* Sys Log.
* Services:
* DNS Client.
* FTP Client.
* LDAP Client.
* NTP Client.
* Applications:
* Email Client.
* Web Browser.
* Processes:
* Placeholder.
"""
def __init__(self, **kwargs):
for key in {"ip_address", "subnet_mask", "default_gateway"}:
if key in kwargs:
if not isinstance(kwargs[key], IPv4Address):
kwargs[key] = IPv4Address(kwargs[key])
super().__init__(**kwargs)
self.connect_nic(NIC(ip_address=kwargs["ip_address"], subnet_mask=kwargs["subnet_mask"]))