-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support ip boardcasting with sync/async stream
formatter and dependency check point check point get network interface Support ip boardcasting with sync/async stream
- Loading branch information
1 parent
9f16edf
commit 0bc0b8b
Showing
14 changed files
with
482 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use etherparse::{icmpv4, IcmpEchoHeader, Icmpv4Header}; | ||
use socket2::{Domain, Protocol, SockAddr, Socket, Type}; | ||
use std::{ | ||
io::{self, Write}, | ||
mem::MaybeUninit, | ||
net::SocketAddr, | ||
thread, | ||
}; | ||
|
||
#[derive(Debug)] | ||
#[repr(u8)] | ||
pub enum IpProtocol { | ||
Icmp = 1, | ||
Igmp = 2, | ||
Tcp = 6, | ||
Udp = 17, | ||
Ipv6 = 41, | ||
Icmpv6 = 58, | ||
UdpLite = 136, | ||
} | ||
|
||
fn main() -> io::Result<()> { | ||
let socket = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4))?; | ||
|
||
let buf = [8, 0, 246, 78, 0, 0, 0, 0, 0, 0, 0, 0, 101, 157, 156, 19]; | ||
let addr = socket2::SockAddr::from(SocketAddr::from(([127, 0, 0, 1], 0))); | ||
socket.send_to(&buf, &addr).unwrap(); | ||
|
||
let mut buf = [MaybeUninit::<u8>::uninit(); 8096]; | ||
let (size, addr) = socket.recv_from(&mut buf)?; | ||
|
||
let inited_buf = buf[..size].as_ref(); | ||
let buffer = inited_buf | ||
.iter() | ||
.map(|u| unsafe { u.assume_init() }) | ||
.collect::<Vec<u8>>(); | ||
println!("Received {} bytes from write socket", size); | ||
println!("{:?}", buffer); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use etherparse::{icmpv4, IcmpEchoHeader, Icmpv4Header}; | ||
use socket2::{Domain, Protocol, SockAddr, Socket, Type}; | ||
use std::{ | ||
io::{self, Write}, | ||
mem::MaybeUninit, | ||
net::SocketAddr, | ||
thread, | ||
}; | ||
|
||
#[derive(Debug)] | ||
#[repr(u8)] | ||
pub enum IpProtocol { | ||
Icmp = 1, | ||
Igmp = 2, | ||
Tcp = 6, | ||
Udp = 17, | ||
Ipv6 = 41, | ||
Icmpv6 = 58, | ||
UdpLite = 136, | ||
} | ||
|
||
fn main() -> io::Result<()> { | ||
println!("Sending packet"); | ||
let send_socket = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4))?; | ||
let addr = SocketAddr::from(([192, 168, 1, 255], 1)); | ||
|
||
let time = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.unwrap() | ||
.as_secs(); | ||
|
||
send_socket.set_broadcast(true)?; | ||
// send_socket.connect(&addr.into()).expect("Failed to connect"); | ||
let echo_message = network_scanner_proto::icmp_v4::Icmpv4Message::Echo { | ||
identifier: 0, | ||
sequence: 0, | ||
payload: time.to_be_bytes().to_vec(), | ||
}; | ||
|
||
let packet = network_scanner_proto::icmp_v4::Icmpv4Packet::from_message(echo_message); | ||
// send_socket.write(&packet.to_bytes(true)).expect("Failed to write"); | ||
send_socket | ||
.send_to(&packet.to_bytes(true), &SockAddr::from(addr)) | ||
.unwrap(); | ||
println!("packet sent"); | ||
let mut buf = [MaybeUninit::<u8>::uninit(); 8096]; | ||
let res = send_socket.recv(&mut buf).expect("Failed to receive"); | ||
println!("Received {} bytes from write socket", res); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// pub struct ResultStream{ | ||
|
||
// } | ||
|
||
// impl tokio_stream::Stream for ResultStream{ | ||
// type Item = &[u8]; | ||
|
||
// } | ||
|
||
// pub async fn boardcast(ip: Ipv4Addr) -> std::io::Result<()>{ | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod broadcast; | ||
pub mod tokio_raw_socket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.