2023-10-03 16:56:35 +01:00
|
|
|
.. only:: comment
|
|
|
|
|
|
|
|
|
|
© Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
|
|
|
|
|
|
|
|
|
|
2024-02-23 08:55:32 +00:00
|
|
|
WebBrowser
|
|
|
|
|
==========
|
2023-10-03 16:56:35 +01:00
|
|
|
|
|
|
|
|
The ``WebBrowser`` provides a client interface for connecting to the ``WebServer``.
|
|
|
|
|
|
|
|
|
|
Key features
|
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
- Connects to the ``WebServer`` via the ``SoftwareManager``.
|
|
|
|
|
- Simulates HTTP requests and HTTP packet transfer across a network
|
|
|
|
|
- Allows the emulation of HTTP requests between client and server:
|
|
|
|
|
- Automatically uses ``DNSClient`` to resolve domain names
|
|
|
|
|
- GET: performs an HTTP GET request from client to server
|
|
|
|
|
- Leverages the Service base class for install/uninstall, status tracking, etc.
|
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
|
^^^^^
|
|
|
|
|
|
|
|
|
|
- Install on a Node via the ``SoftwareManager`` to start the ``WebBrowser``.
|
|
|
|
|
- Service runs on HTTP port 80 by default. (TODO: HTTPS)
|
|
|
|
|
- Execute sending an HTTP GET request with ``get_webpage``
|
|
|
|
|
|
|
|
|
|
Implementation
|
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
- Leverages ``SoftwareManager`` for sending payloads over the network.
|
|
|
|
|
- Provides easy interface for making HTTP requests between an HTTP client and server.
|
|
|
|
|
- Extends base Service class.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example Usage
|
|
|
|
|
-------------
|
|
|
|
|
|
|
|
|
|
Dependencies
|
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
from primaite.simulator.network.container import Network
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.computer import Computer
|
|
|
|
|
from primaite.simulator.network.hardware.nodes.server import Server
|
|
|
|
|
from primaite.simulator.system.applications.web_browser import WebBrowser
|
|
|
|
|
from primaite.simulator.system.services.web_server.web_server_service import WebServer
|
|
|
|
|
|
|
|
|
|
Example peer to peer network
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
net = Network()
|
|
|
|
|
|
|
|
|
|
pc1 = Computer(hostname="pc1", ip_address="192.168.1.50", subnet_mask="255.255.255.0")
|
|
|
|
|
srv = Server(hostname="srv", ip_address="192.168.1.10", subnet_mask="255.255.255.0")
|
|
|
|
|
pc1.power_on()
|
|
|
|
|
srv.power_on()
|
#2248 - Enhances the PrimAITE documentation, covering the Node, network interfaces, Session Manager, Software Manager, PCAP service, SysLog functionality, and network devices like Routers, Switches, Computers, and Switch Nodes. It details their roles, workflows, and integration within the simulation, focusing on frame processing, software management, and logging. The documentation also clarifies the frame reception process, including port checks and application-level dispatching, ensuring a thorough understanding of network operations within the simulation
2024-02-08 22:37:21 +00:00
|
|
|
net.connect(pc1.network_interface[1], srv.network_interface[1])
|
2023-10-03 16:56:35 +01:00
|
|
|
|
|
|
|
|
Install the Web Server
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# web browser is automatically installed in computer nodes
|
|
|
|
|
# IRL this is usually included with an OS
|
|
|
|
|
client: WebBrowser = pc1.software_manager.software['WebBrowser']
|
|
|
|
|
|
|
|
|
|
# install web server
|
|
|
|
|
srv.software_manager.install(WebServer)
|
|
|
|
|
webserv: WebServer = srv.software_manager.software['WebServer']
|
|
|
|
|
|
|
|
|
|
Open the web page
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Using a domain name to connect to a website requires setting up DNS Servers. For this example, it is possible to use the IP address directly
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
# check that the get request succeeded
|
|
|
|
|
print(client.get_webpage("http://192.168.1.10")) # should be True
|