2022年11月7日 星期一

Common Wireshark Filter

Overall

Filter out TCP Keep-Alive packets in Wireshark and not DNS

!(tcp.flags.ack && tcp.len <= 1) and !(dns)

 

 

Element

Filter out TCP Keep-Alive packets in Wireshark

!(tcp.flags.ack && tcp.len <= 1) 

Not DNS

!(dns)






End

Play with libev 4.33 2020-03-18 (2022)

https://libev.cn/api/loop.html



2022年11月3日 星期四

clang-format-10 Ubuntu 20.04 pre-commit hook

https://stackoverflow.com/questions/55965712/how-do-i-add-clang-formatting-to-pre-commit-hook


system

cat /etc/*release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=20.04

DISTRIB_CODENAME=focal

DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"


install

clang-format --version

clang-format version 10.0.0-4ubuntu1 


hook (dont use)

I'm adding the following to the top of my REPO_ROOT/.git/hooks/pre-commit file:

for FILE in $(git diff --cached --name-only)
do
        clang-format -i $FILE
done 

The .clang-format file is placed in the REPO_ROOT. 


chmod a+x pre-commit




hook (use)

#!/usr/bin/env bash

for FILE in *

do

    if [[ "$FILE" =~ \.(c|h|cpp|cc)$ ]]

    then

        echo "processing $FILE"

        clang-format -i $FILE

    else

        echo "skip $FILE"

    fi

done


How to Install WSL 2 on Windows 10 (Updated) (2022 Nov)

 https://www.omgubuntu.co.uk/how-to-install-wsl2-on-windows-10

Hardware

Intel(R) Celeron(R) N5105 @ 2.00GHz
4 Cores 8GB 256GB, AC7265 Wifi only 300Mbps

Install (~5mins)

wsl.exe --install
shutdown /r /t 0
Windows 子系統 Linux 版正在繼續先前的安裝...
正在安裝:Ubuntu

Below may not work
Hyper-V Virtual Switch > Change Private to External > Reboot host
Cannot go to internet > Network > Bridge > Uncheck Hyper-V Extensible Virtual Switch > Can internet

Below should work

https://zhuanlan.zhihu.com/p/488442403

Set-VMSwitch WSL -NetAdapterName Wi-Fi
sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0
sudo ip addr add 192.168.1.150/24 broadcast 192.168.1.255 dev eth0
sudo ip route add 0.0.0.0/0 via 192.168.1.1 dev eth0

Test internet

$ ping -c 3 google.com
$ curl -I https://linuxhint.com/
$ ping -c 2 192.168.1.1
sudo nano /etc/resolv.conf
nameserver 192.168.1.1

File

\\wsl$\Ubuntu\home\ricky

Windows Terminal

Microsoft Store > Terminal > Install
Settings > Default Ubuntu, Last session > Save button

VSCode

Install Extension "WSL(16M)" not "Remote Development" (also Microsoft) not "Remote - SSH" (also Microsoft)







Reference

https://zhuanlan.zhihu.com/p/488442403

让 WSL2 使用桥接网络

WSL2 默认采用了一个 NAT 网络,这对于大多数情况而言都是没有问题的,但是如果想要把 WSL 中的服务直接暴露出来,就不得不考虑做端口转发等问题。以及如果要使用 IPv6,自带的 NAT 方案也不能满足。

因此,这种时候如果能让 WSL2 使用直接接在 NIC 上自然是最好的,可惜 Windows 中没有直接提供这样的配置选项,如果在 Hyper-V 管理器中配置 WSL 网卡为外部网络则会直接报错。

万幸的是,可以使用 PowerShell 直接进行配置,本文则记录使用 PowerShell 让 WSL2 用上桥接网络的方法。

以下内容需要以管理员身份在PowerShell内执行。

一切开始之前首先需要启动 WSL,直接运行 wsl 即可,这样 WSL 的网卡才会被自动创建出来。

然后退回 PowerShell,运行 Get-NetAdapter获取所有的网卡信息,记录想要桥接到的网卡,例如 Wi-Fi 或 Ethernet 等等,下面以 Wi-Fi 为例。

执行以下代码:

Set-VMSwitch WSL -NetAdapterName Wi-Fi

即可将 WSL 使用的网卡桥接到 Wi-Fi 这个网卡之上。

接下来进入 WSL 配置 IP 地址和网关,例如网关为 192.168.1.1,IP 设置为 192.168.1.150/24:

sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0
sudo ip addr add 192.168.1.150/24 broadcast 192.168.1.255 dev eth0
sudo ip route add 0.0.0.0/0 via 192.168.1.1 dev eth0

接下来更新名称解析服务器地址,执行 nano /etc/resolv.conf,修改其中内容为 nameserver 192.168.1.1,然后按 Ctrl+X保存退出即可。




End


2022年10月11日 星期二

Use RSync to reploy from local to remote on Ubuntu 20.04 (2022)

 https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/


rsync -avzh /root/rpmpkgs root@192.168.0.141:/root/rpmpkgs


2022年10月5日 星期三

Docker commands 2022


check

sudo docker ps -a



remove

 sudo docker stop $(sudo docker ps -a -q)

sudo docker rm $(sudo docker ps -a -q)

sudo docker volume prune -f

sudo docker image prune -a


2022年9月21日 星期三

How to Setup Python Script Autorun As a Service in Ubuntu 20.04 (2022)

 https://websofttechs.com/tutorials/how-to-setup-python-script-autorun-in-ubuntu-18-04/

 

Dummy Python Program


https://www.digitalocean.com/community/questions/trying-to-change-workingdirectory-of-systemd-service-unit

[Service]

WorkingDirectory=/home/pi

 

 

nano /home/ricky/apply.py

#!/usr/bin/python3
import time, datetime, os
from pathlib import Path
Path("./logs/").mkdir(parents=True, exist_ok=True)
filename: str = datetime.datetime.now().strftime(f"./logs/%Y%m%d.%H%M%S.pid.{os.getpid()}.log")
while True:
    line: str = str(datetime.datetime.now())
    print(line)
    with open(filename, "a") as outfile:
        outfile.write(line+'\n')
    time.sleep(2)

sudo nano /lib/systemd/system/apple.service

[Unit]
Description=Apple Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service]
Type=simple
WorkingDirectory=/home/ricky/
ExecStart=/usr/bin/python3 /home/ricky/apple.py
StandardInput=tty-force

[Install]
WantedBy=multi-user.target


sudo systemctl daemon-reload

sudo systemctl enable apple
sudo systemctl start apple

sudo systemctl status apple

sudo systemctl restart apple

sudo systemctl stop apple
sudo systemctl disable apple


Dummy Python Program to python -m with venv

service
=======

sudo nano /lib/systemd/system/my_app.service

[Unit]

Description=MyApp  

After=multi-user.target

Conflicts=getty@tty1.service

[Service]

Type=simple

WorkingDirectory=/home/ricky/my_app

ExecStart=/home/ricky/my_app/venv/bin/python3 -m my_app --cfg /home/ricky/my_app/quant-server.yml

StandardInput=tty-force

[Install]

WantedBy=multi-user.target


systemctl
=========

sudo systemctl daemon-reload
sudo systemctl enable my_app
sudo systemctl start my_app
sudo systemctl status my_app
sudo systemctl restart my_app
sudo systemctl stop my_app
sudo systemctl disable my_app


2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...