NetBurner Ping From Web Example
Overview
The Ping From Web Example demonstrates how to create a web-based network diagnostic tool using the NetBurner platform. This example creates a web server that allows users to ping remote hosts (by IP address or DNS name) through a simple HTML form interface, showcasing HTTP POST handling and network diagnostics capabilities.
Application Description
This embedded web application provides a web-based ping utility that runs on a NetBurner device. Users can enter an IP address or hostname through a web form, and the device will perform a ping operation and display the results. This example demonstrates form handling, DNS resolution, and ICMP ping functionality in an embedded environment.
Key Features
- Web-Based Interface: Simple HTML form for entering ping targets
- DNS Resolution: Supports both IP addresses and hostnames
- HTTP POST Handling: Processes form submissions using NetBurner's HTTP POST framework
- Network Diagnostics: Performs ICMP ping operations with response time measurement
- Real-Time Results: Displays ping results directly in the web browser
- Error Handling: Provides feedback for failed DNS resolution and ping timeouts
How It Works
Application Flow
- Initialization: The
UserMain() function initializes the network stack
- Diagnostics: Enables system diagnostics for debugging (should be removed in production)
- Web Server: Starts the HTTP server on port 80
- POST Handler: Registers
PingCallBack to handle form submissions to "pingpost.html"
- Network Wait: Waits up to 5 seconds for active network connection
- Main Loop: Enters infinite loop with 1-second delays
Ping Process
- Form Submission: User enters IP address or hostname and submits form
- Parameter Extraction:
PingCallBack extracts the "paddr" parameter from POST data
- DNS Resolution: Uses
GetHostByName() to resolve hostname to IP address
- Ping Execution: Calls
Ping() function with 2-second timeout
- Result Display: Shows ping response time or failure message
- Return Navigation: Provides link back to the main ping form
Web Interface
The application serves a simple HTML form (index.html) that includes:
- Text input field for IP address or hostname
- Submit button to initiate ping
- Results are displayed on a separate page with navigation back to the form
Technical Details
Dependencies
- NBRTOS: NetBurner Real-Time Operating System
- Network Stack: Built-in TCP/IP stack with ICMP support
- HTTP Server: Integrated web server with POST handling
- DNS Client: Built-in DNS resolution functionality
Key Functions
System Requirements
- NetBurner compatible hardware
- Network connectivity (Ethernet or WiFi depending on platform)
- NNDK (NetBurner Network Development Kit)
Usage
- Compile: Build the application using the NetBurner development environment
- Deploy: Load the application onto your NetBurner device
- Connect: Ensure the device is connected to your network
- Access: Open a web browser and navigate to the device's IP address
- Ping: Enter an IP address or hostname in the form and click "Ping"
- View Results: The ping results will be displayed with response time or error message
Example Usage
Successful Ping
Enter "google.com" in the form:
- Address resolved to [142.250.191.46]
-
Ping Responded in 234 Ticks
int Ping(const IPADDR &to, uint16_t id, uint16_t seq, uint16_t maxwaitticks, int size=32)
Generic ping function that uses IPv6 when IPv6 is enabled.
Definition ip.h:1008
Failed Ping
Enter "nonexistent.domain.com" in the form:
- Failed to resolve address
Development Notes
Production Considerations
- Remove
EnableSystemDiagnostics() call for production deployments
- Consider adding input validation for the ping target field
- Implement rate limiting to prevent ping flooding
- Add authentication for administrative access
- Consider adding traceroute or other network diagnostic tools
Customization
This example can be extended to include:
- Multiple ping targets in a single request
- Ping history and statistics
- Network topology discovery
- Port scanning capabilities
- Integration with SNMP monitoring
- Automated network health checks
Security Notes
- Ping functionality can be used for network reconnaissance
- Consider restricting ping targets to specific IP ranges in production
- Implement proper input sanitization to prevent injection attacks
- Add logging for audit trails of ping requests
Console Output
When running, the application displays:
Web Application:
Ping From Web
NNDK Revision: [Version Information]
Error Handling
The application handles several error conditions:
- Empty ping target: "Ping address empty"
- DNS resolution failure: "Failed to resolve address"
- Ping timeout/failure: "Ping Failed"
- Successful ping: "Ping Responded in X Ticks"