All checks were successful
continuous-integration/drone/tag Build is passing
Signed-off-by: Jochen Maes <jochen@sejo-it.be>
22 lines
709 B
Rust
22 lines
709 B
Rust
use std::{net::{TcpListener, TcpStream}, io::{Write}};
|
|
|
|
|
|
fn main() {
|
|
let listener = TcpListener::bind("[::]:4242").unwrap();
|
|
|
|
for stream in listener.incoming() {
|
|
let stream = stream.unwrap();
|
|
|
|
throw_ip_back(stream);
|
|
}
|
|
}
|
|
|
|
fn throw_ip_back(mut stream: TcpStream) {
|
|
let status_line = "HTTP/1.1 200 OK";
|
|
let raw_addr = stream.peer_addr().unwrap().ip().to_string();
|
|
println!("{}", raw_addr);
|
|
let content = format!("{}",raw_addr.replace("::ffff:", ""));
|
|
let length = content.len();
|
|
let response = format!("{status_line}\r\nContent-Length: {length}\r\nContent-Type: text/html; charset=utf-8\r\n\r\n{content}");
|
|
stream.write_all(response.as_bytes()).unwrap();
|
|
} |