0%

今天想要分享 WIFI 筆記跟,工具,和 CLI 指令

Capture Wireless OTA Beacon

不同平台有不同抓法,我在這用 Linux 分享,因為它是免費也最簡單用。如果你有 MAC 那是最簡單方式,甚麼都不用安裝你需要有 wireshark。

There’re many type of tool you can use to cpature, but I’m going to use the most easiest way to capture Wireless Beacon Packet OTA(AIR) packet. I will be using Linux which is free and easy to setup. If you have MAC then it’s more easy no need to install any tool, just need a wireshark then you can capture.

Step1 Install airmon-ng

Linux Distribution: Ubuntu

1
sudo apt install airmon-ng

Step2 Check your Wirless interface

Please noted down your wirless interface ex: wlan0

1
ifconfig #to list all interface
Read more »

SSH Automatic Command

I am showing how to use some third party tool to run SSH to remote connection and run some some command.

TeraTerm

SSH Connection

  • Create ttl file
    The ttl file is macro script, that TeraTerm can be able to load. In this file you have to add the command you want to execute after login ssh.

Below this terateam script just use SSH to make connection. User no need to enter account and password. It will just automatic open SSH connection then you can type command

1
2
3
4
5
timeout=10
pause 5

connect '192.168.1.254 /ssh /auth=password /user=root /passwd=1234567890 /nosecuritywarning'

If you want to run SSH command you can refer below example this will run command and close terateam.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
timeout=10
pause 5
connect '192.168.1.254 /ssh /auth=password /user=root /passwd=1234567890 /nosecuritywarning'

pause 2
sendln 'cat /etc/arcwrt_release'

;sendln 'tr69_trigger setvalue Device.ManagementServer.EnableCWMP=1'
pause 4

;sendln 'tr69_trigger setvalue Device.ManagementServer.URL="http://172.21.201.112:8080/acs"'
;pause 5

closett

If you want to check your ttl script work or not, just open terateam control>macro and load the file will see if script work or not.

Read more »

Setup Multiply Github account via SSH

1. Generate separate SSH keys

1
2
3
4
5
# personal account
ssh-keygen -t ed25519 -C "email@personal_mail.com" -f ~/.ssh/id_personal

#work account
ssh-keygen -t ed25519 -C "email@work_mail.com" -f ~/.ssh/id_rsa_work_user1

it will generate file private and public:

1
2
3
4
~/.ssh/id_personal
~/.ssh/id_personal.pub
~/.ssh/id_rsa_work_user1
~/.ssh/id_rsa_work_user1.pub

2. Add public keys to GitHub

  1. GitHub → Settings
  2. SSH and GPG keys
  3. New SSH key
  4. Paste the .pub file content

3. Registering the new SSH Keys with the ssh-agent

1
2
3
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_personal
ssh-add ~/.ssh/id_rsa_work_user1
  • List key: ssh-add -l
  • 刪除則使用: ssh add -d ~/.ssh/id_personal
  • 刪除全部: ssh-add -D
Read more »

Today like to share some tips for wireshark, which some of you might not notice. Wireshark is a free tool that let you capture packet or monitor your network status. This is a mostly common tool if your are testing or debug network problem.

Remote Capture packet

You can use remote tool like ssh related tool to capture packet. This is useful if you don’t want to save in your router, instead save in your labtop.

Thi smethod allow you to remote capture wireshark and save the file in your labtop, without worry about the disk space or memory.

WireShark filter trick

Filter IP address

When you want to filter Ip address for long period of time then you need to use below setting, else it will capture a massive file.

Filter range of condition or port

Read more »

This post would like to share some of the commonly use code can be easier use, you can think of cheatsheet for basic python code. This allow you to copy the code if you want to use it.
這篇筆記只想分享一些基本或常用到的程式可以用,,可以想成懶人包。

Basic Code

Exception capture Error on code

If you every had some experience to write code to do specfic cacultion like division of 0 and when print it will occcur Error. To not show the Error, we can use the try and exception related code.

source: Youtube:@Cod1ngTogether

  • Error Occur
    1
    2
    3
    4
    num1= 10
    num2= 0
    result = num1/num2
    print(result) #ZeroDivisionError: division by zero
    it will occur Error like below:
    1
    2
    3
    4
    File "C:\new\basic_ex\try_expection.py", line 11
    except exception e:
    ^
    SyntaxError: invalid syntax

Soluttion: for this code is to add try and exception

  • Try exception
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    try:
    num1= 10
    num2= 0
    result = num1/num2
    print(result) #ZeroDivisionError: division by zero
    #catch ZeroDivisionError error
    except ZeroDivisionError:
    print('Error: not able to divide by zero, please try again thanks!!!')

    #catch every error it occur
    except Exception as e:
    print(f"Error ocurred:{e}")

output: Error: not able to divide by zero, please try again thanks!!!

  • Real world case use function
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    def readFile(filename):

    try:
    with open(filename, "r") as file:
    content= file.read()
    except FileNotFoundError:
    print('File not found!!! Help you create one....')
    with open("missingfile.txt", "w") as file:
    content= "Hello World"
    file.write(content)
    else:
    print("File Read successfully")
    return content
    finally:
    print("Closing FIle")
    if __name__ == '__main__':
    filename= input('Your filename(ex test.txt): ')
    content= readFile(filename)
    print(content)
Read more »

This is my network note which record different linux and debug command

Debug Using tool

Nmap port scan

Scan port can use either:

nc -vz: quick, lightweight probe (good for QA spot checks).
nmap: more detailed: can scan ranges, detect service versions, OS fingerprints, etc.

1
nmap -Pn -p 21 172.21.201.16

Scan port option:

-Pn: don’t ping first (treat host as alive)
-p 21: scan only port 21

Netcat: scan and send traffic

The nc command allow you to debug like send a small traffic or scan port just like nmap

Scan if a port is open like nmap

Syntax: nc -vz ip-add port

-v: verbose
-z: just scan for listening service (don’t send data)

Read more »

This is the automatic script which i will be using on debug or reproduce issue like stability test for Network.

Shell Script

This script will be added inside console, keep running and logged log.

syntax of bashscript:

1
2
3
4
5
6
7
8
#!/bin/sh
while true
do
echo "Polling EthPhy Status !"


sleep 1 ;
done

Read top evey 60 second and logf file

1
2
3
4
5
6
while true; do
date
free
top -b -n1 | head -15
sleep 60
done >> /tmp/memlog.txt

check bbu status every 10 second

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
htx_pcd_app -a start -r BATTERY_HOST
while [ 1 ];
do
date
echo "####################"
battery_host -m 1 -s
echo "###################"
echo ""
echo "================"
uci show bbu -c /var/tmp
echo "================"
sleep 10
echo ""
echo ""
done

TTL Macro Script

Read more »

今天想要分享快速使用 UV 方式,不太會去多介紹它,如果你想更了解可以去我這篇文章有寫很多內容,但它是英文。我希望這裡放一些可以馬上就已用指令。

我想信大家都有用過 Python 都知道用 venv 是為了要獨立環境,用 pip or poetry 是為了裝套件等等。有時候用起來很麻煩,UV 解掉所以問體。剛剛提到的兩個是不同工具,UV 把這些用再一起,換句話說就是一個 UV 就可以有虛擬環境,套件管理等等功能,最重要是它是用 RUST 開發的因此很快。如果想了解更多請到可以到它官網看。

Traditional Way 傳統方式 (venv)

下面方式就是我們以前最常用的:

  • create venv
  • activate venv
  • pip 安裝套件
  • 把套件匯出
1
2
3
4
5
6
7
8
mkdir withoutUV_Project #create a project
cd withoutUV_Project
python3 -m venv .venv #create a virtual env
cd withoutUV_Project
.\Scripts\activate #activate virtual env
which python3
pip3 install numpy pandas selenium
python3 freeze > requirements.txt

今天想要分享快速使用 UV 方式,不太會去多介紹它,如果你想更了解可以去我這篇文章有寫很多內容,但它是英文。我希望這裡放一些可以馬上就已用指令。

我想信大家都有用過 Python 都知道用 venv 是為了要獨立環境,用 pip or poetry 是為了裝套件等等。有時候用起來很麻煩,UV 解掉所以問體。剛剛提到的兩個是不同工具,UV 把這些用再一起,換句話說就是一個 UV 就可以有虛擬環境,套件管理等等功能,最重要是它是用 RUST 開發的因此很快。如果想了解更多請到可以到它官網看。

Notice when you just install dependency like request or selenium, it install other package, this is called the transitive dependencies or sub-dependency. Some packages rely on other internal packages (transitive dependencies).

UV 安裝

Read more »

我想大家都知道 SSH 是什麼,也很多人應該已經會用 SSH Key 可以免輸入密碼就可以 SSH 登入。我想信大家用 github 應該都會用,但我今天不是要用 github 我要用 ubuntu 當作 SERVER, window 當做 client. 其實做法是一樣,github server 當作我自己 ubuntu server。

很多時候你用 github 可能一些 server 上運作可能你不太知道背後的運動是如何,今天可以介由者個範例可以理解更多以真實 server

請務必先安裝 openssh 能用

1
sudo apt install openssh-server
  • 公鑰跟私鑰是一組,這樣才可以連線,他們會做連結
    • Private Key 私鑰: 要存在你自己電腦
    • Public Key 私鑰: 要放在本地端要連到 Sever。

client 建 Key

這個方式是最常用的方式,就跟 github 一樣,本地端會建 private 和 public key,然後把 public key 傳到 server 上面並加入 Server 上的 ~/.ssh/authorized_keys 檔案中。)

以這個範例我本地端(Local/Client)要用 SSH 遠端到 Server 端,我需要把我的公鑰(public key)傳到 Server 這樣私鑰做連線會跟 Server 公鑰比對,是同一組就會連線。

  • 在 SSH 連線中,Client 會先產生一組公鑰(public key)和私鑰(private key)。
  • 公鑰會放到 Server 上,而私鑰只保留在 Client。

當 Client 嘗試連線時,會使用私鑰(private key)來進行驗證,而 Server 會利用它儲存的公鑰來驗證 Client 的私鑰是否正確,確認是同一對金鑰後,即可成功連線,我下面我教如何做到。

Read more »