# 为虚拟网络接口 utun0 配置 IP 地址 10.0.0.33 和子网掩码 255.255.255.0 网关地址 10.0.0.1
sudo ifconfig utun0 10.0.0.33 10.0.0.1 netmask 255.255.255.0
# 配置目标地址是网段 192.168.1.0/24 的流量走 10.0.0.1 网关
sudo route add 192.168.1.0/24 10.0.0.1
# 将 6.11.20.10 这个单一地址(因为掩码是 32)路由到 192.168.4.1 这个网关
sudo route add 6.11.20.10/32 192.168.4.1
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
use std::sync::Arc; | |
use tokio::sync::Notify; | |
#[tokio::main] | |
async fn main() { | |
let notify = Arc::new(Notify::new()); | |
// 注册两个等候者 | |
let notified1 = notify.notified(); | |
let notified2 = notify.notified(); |
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
// | |
// DnsProxy.h | |
// | |
#import <Foundation/Foundation.h> | |
/** | |
* DNS Proxy | |
* | |
* This class is responsible for setting up a DNS proxy server that listens on a local port and |
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
fn handle_icmp_echo_request(u: &ipstack::stream::IpStackUnknownTransport) -> Result<()> { | |
use etherparse::{IcmpEchoHeader, Icmpv4Header, Icmpv6Header, IpNumber}; | |
assert!(u.ip_protocol() == IpNumber::ICMP || u.ip_protocol() == IpNumber::IPV6_ICMP); | |
if u.src_addr().is_ipv4() { | |
let (icmp_header, req_payload) = Icmpv4Header::from_slice(u.payload()).map_err(|e| Error::from(e.to_string()))?; | |
if let etherparse::Icmpv4Type::EchoRequest(req) = icmp_header.icmp_type { | |
log::info!("#0 ICMPv4 echo"); | |
let echo = IcmpEchoHeader { id: req.id, seq: req.seq }; | |
let mut resp = Icmpv4Header::new(etherparse::Icmpv4Type::EchoReply(echo)); | |
resp.update_checksum(req_payload); |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/socket.h> | |
void child(int sock) { | |
char buf[1024]; | |
while (1) { | |
ssize_t n = read(sock, buf, sizeof(buf)); | |
if (n <= 0) { |
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
use log::{info, LevelFilter}; | |
use reqwest; | |
use serde_json::Value; | |
use std::fs::File; | |
use std::io::prelude::*; | |
use std::time::SystemTime; | |
use tokio; | |
// https://github.com/shadowsocks/shadowsocks-rust/blob/master/acl/genacl_proxy_gfw_bypass_china_ip.py |
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
use core::{ | |
future::Future, | |
pin::Pin, | |
task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, | |
}; | |
use std::collections::VecDeque; | |
fn dummy_raw_waker() -> RawWaker { | |
fn no_op(_: *const ()) {} | |
fn clone(_: *const ()) -> RawWaker { |
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
#include <sys/types.h> | |
#include <sys/ioctl.h> | |
#include <sys/socket.h> | |
#include <sys/sys_domain.h> | |
#include <sys/kern_control.h> | |
#include <net/if_utun.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <syslog.h> |
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
use libc::{ | |
c_int, c_long, c_uint, c_void, freeifaddrs, getifaddrs, ifaddrs, sockaddr, sockaddr_in, | |
sockaddr_in6, AF_INET, AF_INET6, IFF_BROADCAST, IFF_LOOPBACK, IFF_MULTICAST, IFF_RUNNING, | |
IFF_UP, RTF_GATEWAY, | |
}; | |
use std::{ | |
ffi::CStr, | |
io, mem, | |
net::{IpAddr, Ipv4Addr}, | |
ptr, |
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
// | |
// tokio = { version = "1.36", features = ["full"] } | |
// | |
use std::{env, error::Error}; | |
use tokio::{ | |
io::{AsyncReadExt, AsyncWriteExt}, | |
net::{TcpListener, ToSocketAddrs, UdpSocket}, | |
}; | |
const TCP_TIMEOUT: u64 = 10 * 1000; // 10sec |
NewerOlder