Recent Posts
-
September 29, 2022
Iptables匹配udp包的长度和payload里面的内容
iptables -t raw -I PREROUTING 1 -p udp -m length --length 52 -m u32 --u32 "32 & 0xFFFFFFFF = 0x584D5359 && 44 & 0xFFFFFFFF= 0x464c5559" -j DROP length这个target可以匹配包长度, --length 为wireshark看到ip头的total length的数值 u32 匹配udp包的内容, “偏移地址16”...
-
August 29, 2022
Golang设置windows注册表和系统网络代理
官方有一个修改注册表的库。 https://pkg.go.dev/golang.org/x/sys/windows/registry修改windows系统代理,要修改注册表的这两个键HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable 整型类型HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\...
-
August 18, 2022
Tcp的close_wait 状态
发现http服务器有一个bug,有一个CLOSE_WAIT状态的socket导致 反复的读取死循环100%,只有重启进程才能修复。网上找的 https://stackoverflow.com/questions/15912370/how-do-i-remove-a-close-wait-socket-connectionCLOSE_WAIT means that the local end of the connection has received a FIN from the othe...
-
August 12, 2022
Nft使用sets匹配源ip和目的ip的方法 可以取代ipset
nftables的sets比ipset iptables这些灵活一些,但感觉也复杂了一些。nft list rulesetnft list tablesnft list table ip natnft flush table ip example_tablenft delete table ip example_tablenft add table inet example_tablenft add set inet example_table example_set '{ type ...
-
August 07, 2022
Ffmpeg下载m3u8视频和合并加密ts视频流
```textexport http_proxy="http://127.0.0.1:8000" # 使用代理/d/ffmpeg-5.0.1-full_build/bin/ffmpeg.exe -i 'http://.../playlist.m3u8' -c copy output.mp4 下载视频流但有的网站m3u8单独下载不了,可能有cookie之类的校验,只能在浏览器里面下载m3u8文件。m3u8是一个列表,包含多个ts文件, 单独下载ts文件下来,然后使用下面的命令合并成mp...
-
July 22, 2022
Socket的ip_freebind选项可以提前绑定一个本机不存在的ip
启用这个选项后,可以绑定一个本机不存在的ip。 int freebind = 1; setsockopt(sockfd, IPPROTO_IP, IP_FREEBIND, &freebind, sizeof(freebind));
-
July 15, 2022
Linux内核的tcp和udp接受函数和无效socket丢包统计
tcp_v4_rcv { // tcp的接函数lookup: sk = __inet_lookup_skb(&tcp_hashinfo, skb, __tcp_hdrlen(th), th->source, th->dest, sdif, &refcounted); if (!sk) goto no_tcp_socket;no_tcp_socket: drop_reason = SKB_DROP_REASON_NO_SOCKET; ...
-
July 12, 2022
Linux的c程序和动态链接库的初始化函数类似golang里面的init函数
dlopen 支持_init函数的 https://man7.org/linux/man-pages/man3/dlopen.3.html不过现在建议使用gcc的constructor attribute,像下面这样定义,xxxx_init 会在初始化阶段dlopen返回之前被调用,和main入口之前被调用吧 destructor 函数void __attribute__((constructor)) xxxx_init(void);void __attribute__((destruct...
-
July 12, 2022
Iconv的gb2312和utf8编码转换
GBK 兼容 GB2312, 都兼容Ascii 。如果一个utf-8字符串的所有字节都小于128那就是ASCII 不需要转换了吧,#include <stdio.h>#include <stdlib.h>#include <string.h> #include <iconv.h>int encoding_convert(const char *tocode, const char *fromcode, ...
-
July 11, 2022
Awk打印不在第二个文件里面内容
去重 相当于 sort | uniqawk '!x[$0]++ 1.txt求第二列的平均值,每隔360项打印一次awk '{ s += $2; if (NR % 360 == 0) { print s/360; s = 0;}}' 1.txt下面语句打印第二个文件不出现在第一个文件中的第一列 第一个文件 NR 等于 FNR(file NR),awk 'NR==FNR{a[$0]++;next}NR!=FNR{if(!a[$0])print $0}' test1.txt test2.txt