A small CLI tool written in C++ to parse Apache Tomcat server.xml configuration files and discover all configured ports.
- Automatic Discovery:
- Searches current directory for
server.xmlorconf/server.xml - Recursively walks directories to find all server.xml files
- Searches current directory for
- Port Discovery: Discovers all configured ports:
- Server ports: The shutdown port configured in the
<Server>element - Connector ports: HTTP, HTTPS, AJP connector ports
- Redirect ports: Ports used for redirecting traffic (e.g., HTTP to HTTPS)
- Server ports: The shutdown port configured in the
- Multi-file Support: Can process multiple server.xml files in one run
- Simple CLI: Easy-to-use command-line interface with optional arguments
- Fast and Lightweight: No external dependencies, built with C++17
- CMake 3.10 or higher
- C++17 compatible compiler (GCC, Clang, or MSVC)
mkdir build
cd build
cmake ..
cmake --build .This will create the tomport executable in the build directory.
The project includes comprehensive unit and integration tests:
# Build and run all tests
cd build
ctest --output-on-failure
# Or run test executables directly
./build/tomport_unit_tests
./build/tomport_integration_testsSee tests/README.md for more details on the test suite.
tomport [options] [path]-m, --mode <mode>- Output mode:list(default),simple, ortable-h, --help- Show help message
-
list (default) - Hierarchical tree view showing:
- File path (for multiple files)
- Server port
- Each service and its connectors with ports and redirect ports
-
simple - Plain minimal output:
- Server port on first line
- Then connector ports
- Then redirect ports (if different from connector ports)
-
table - Formatted table with columns:
- Server Port
- Service Name
- Connector Port
- Redirect Port
The tool supports three modes of operation:
- No path: Automatically searches for
server.xmlorconf/server.xmlin the current directory - File path: Parse a specific server.xml file
- Directory path: Recursively search a directory for all server.xml files
# Search current directory (default list mode)
./build/tomport
# Parse a specific file with simple output
./build/tomport -m simple sample-server.xml
# Recursively search with table output
./build/tomport --mode table /opt/tomcat
# Parse specific file with list mode
./build/tomport /opt/tomcat/conf/server.xml
# Show help
./build/tomport --helpServer Port: 8005
├─ Service: Catalina
├─ Connector Port: 8080 (Protocol: HTTP/1.1) → Redirect: 8443
└─ Connector Port: 8009 (Protocol: AJP/1.3) → Redirect: 8443
8005
8080
8443
8009
Server Port Service Name Connector Port Redirect Port
--------------------------------------------------------------------
8005 Catalina 8080 8443
Catalina 8009 8443
Found 2 server.xml file(s) in '/opt/tomcat-instances':
- /opt/tomcat-instances/instance1/conf/server.xml
- /opt/tomcat-instances/instance2/conf/server.xml
File: /opt/tomcat-instances/instance1/conf/server.xml
------------------------------------------------------------
Server Port: 8005
├─ Service: Catalina
└─ Connector Port: 8080 (Protocol: HTTP/1.1) → Redirect: 8443
File: /opt/tomcat-instances/instance2/conf/server.xml
------------------------------------------------------------
Server Port: 9005
├─ Service: App2Service
└─ Connector Port: 9080 (Protocol: HTTP/1.1) → Redirect: 9443
A sample server.xml file is included in the repository for testing purposes.
The tool uses the TinyXML2 library to parse XML files. It:
- Loads the specified
server.xmlfile(s) - Parses the hierarchical structure:
<Server>elements withportattributes (shutdown port)<Service>elements withnameattributes<Connector>elements withport,protocol, andredirectPortattributes
- Extracts port numbers and associated information
- Displays the results in the selected output format (list, simple, or table)
This project includes GitHub Actions workflows for continuous integration and releases:
- CI Workflow: Automatically builds and tests the project on every push and pull request to main/master branches
- Release Workflow: Creates Linux release binaries when a new tag is pushed
To create a new release with compiled binaries:
-
Tag your commit with a version number:
git tag v1.0.0 git push origin v1.0.0
-
The workflow will automatically:
- Build the project on Linux
- Run tests
- Package the binary with documentation
- Create a GitHub release with the
tomport-linux-x64.tar.gzartifact
You can also manually trigger a build from the Actions tab on GitHub.
Pre-built Linux binaries are available in the Releases section. Download and extract:
wget https://github.com/JonasGao/tomport/releases/download/v1.0.0/tomport-linux-x64.tar.gz
tar -xzf tomport-linux-x64.tar.gz
cd tomport-linux-x64
./tomport sample-server.xmlThis project uses TinyXML2, which is licensed under the zlib license.