This project aims to provide a simulation of a small partial replica of a IP Printer web server, allowing to recreate an endpoint that offers a CSV file to be downloaded.
This feature was built to complement the printer-monitoring project
-
Docker
-
By using Docker and Docker Compose, it is possible to create various containers in order to simulate we have multiple IP Printers connected directly in our physical network
-
So, this way we can use those IP addresses from each container and writing them in the
devices.json
file available at theapp
folder on printer-monitoring project to make some tests
-
-
FastAPI
- FastAPI is a web framework for building APIs with Python 3. Only a small amount of what this framework offers has been used
-
In this project, network chosen was 192.168.1.0/24 with a gateway of 192.168.1.1 and containers were configured to obtain the following IP addresses: 192.168.1.201/24 and 192.168.1.202/24
-
So, unless your network be the same and you have those specific IP addresses available to assign to new hosts, you should adapt this docker-compose.yml file to your network specs
-
Driver
ipvlan
is needed to make containers obtain an IP address directly from your physical network. Unfortunately, it is not available on Windows systems at the moment. -
So, to mitigate this problem an Ubuntu VM has been deployed on Windows. Inside that VM, docker and docker compose were installed.
- A CSV file downloaded from a Brother HL-1210W Series printer is provided to make it available in the correspondant endpoint to be downloaded
-
Root Endpoint:
/
- This endpoint was created to test the availability of the API
- It returns a dictionary with a message and datetime information
-
CSV Endpoint:
/etc/mnt_info.csv
- This endpoint was created to download a maintenance CSV file
- It returns the CSV file
-
Install Docker and Docker Compose
sudo apt-get update && sudo apt-get install docker docker-compose -y
-
Clone this repository
git clone https://github.com/mvarrone/simulate-ip-printer-webserver.git && cd simulate-ip-printer-webserver
-
Run Docker Compose
a) Start
docker-compose up -d
b) Stop
docker-compose down
-
Test the containers are working by using a web browser and visiting
http://192.168.1.201/
andhttp://192.168.1.202/
You can also use
curl
orPostman
If working, you should see something like:
{"message":"App is working","time":"2023-04-28T06:41:52.060170"}
-
Add data printer inside the
devices.json
file. It must be added in the format of Python 3 dictionariesExample:
{ "protocol": "http", "ip_address": "192.168.1.201", "port": 80, "path": "etc", "csv_filename": "mnt_info.csv" }
-
You can now test the other project with the new available hosts
Contributions are welcome! Please create a pull request with any changes or improvements you would like to make
This project is licensed under the MIT License. See the file for details