public ip
This commit is contained in:
+9
-2
@@ -52,7 +52,7 @@ pub fn router() -> std::io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run() -> std::io::Result<()> {
|
pub fn run(current_ip: (u8, u8, u8, u8)) -> std::io::Result<()> {
|
||||||
let listener = TcpListener::bind("0.0.0.0:7878")?;
|
let listener = TcpListener::bind("0.0.0.0:7878")?;
|
||||||
let mut connections: Vec<[u8; 6]> = Vec::new();
|
let mut connections: Vec<[u8; 6]> = Vec::new();
|
||||||
|
|
||||||
@@ -70,7 +70,14 @@ pub fn run() -> std::io::Result<()> {
|
|||||||
if let Some(con) = connections.last() {
|
if let Some(con) = connections.last() {
|
||||||
stream.write_all(con)?;
|
stream.write_all(con)?;
|
||||||
} else {
|
} else {
|
||||||
let default_addr = [0, 0, 0, 0, 0x1E, 0xC7];
|
let default_addr = [
|
||||||
|
current_ip.0,
|
||||||
|
current_ip.1,
|
||||||
|
current_ip.2,
|
||||||
|
current_ip.3,
|
||||||
|
0x1E,
|
||||||
|
0xC7,
|
||||||
|
];
|
||||||
stream.write_all(&default_addr)?;
|
stream.write_all(&default_addr)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+40
-2
@@ -1,3 +1,41 @@
|
|||||||
fn main() {
|
use std::{
|
||||||
ghostnet_rs::gateway::run().unwrap();
|
io::{Read, Write},
|
||||||
|
net::TcpStream,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
let mut stream = TcpStream::connect("ipv4.icanhazip.com:80")?;
|
||||||
|
|
||||||
|
// Send raw HTTP request
|
||||||
|
let request = "GET / HTTP/1.1\r\n\
|
||||||
|
Host: ipv4.icanhazip.com\r\n\
|
||||||
|
Connection: close\r\n\
|
||||||
|
\r\n";
|
||||||
|
stream.write_all(request.as_bytes())?;
|
||||||
|
|
||||||
|
// Read full response
|
||||||
|
let mut response = String::new();
|
||||||
|
stream.read_to_string(&mut response)?;
|
||||||
|
|
||||||
|
// Extract body after headers
|
||||||
|
if let Some(pos) = response.find("\r\n\r\n") {
|
||||||
|
let body = response[pos + 4..].trim();
|
||||||
|
|
||||||
|
// Parse into tuple (u8, u8, u8, u8)
|
||||||
|
let octets: Vec<u8> = body
|
||||||
|
.split('.')
|
||||||
|
.filter_map(|s| s.parse::<u8>().ok())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if octets.len() == 4 {
|
||||||
|
let ip_tuple = (octets[0], octets[1], octets[2], octets[3]);
|
||||||
|
ghostnet_rs::gateway::run(ip_tuple)?;
|
||||||
|
} else {
|
||||||
|
eprintln!("Invalid IPv4 address format: {}", body);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Invalid HTTP response");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user