# Blog ## Postman Connect to OCPP server through websocket URL ![step1_protocol_select](https://hackmd.io/_uploads/SJUO8UyL-e.png) ![step2_connect](https://hackmd.io/_uploads/S1DdL8kIWg.png) ![step3_Tx](https://hackmd.io/_uploads/B1w_II1U-e.png) ![step4_NewResult](https://hackmd.io/_uploads/BJmk_IyU-e.png) ## IP script Windows11 set_network_config_DHCP.bat ```` @echo off REM First check to see if the script is running with elevated privileges. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config" REM If the previous command failed to write the temporary file, REM it means that we do not have permissions to write, and therefore REM do not have administrative privileges. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin REM <Your original batch commands go here> echo Setting Ethernet to DHCP... netsh interface ip set address "Ethernet" dhcp netsh interface ip set dnsservers "Ethernet" dhcp echo Ethernet is set to DHCP. endlocal echo Running with administrative privileges. pause ```` set_network_config_static.bat ```` @echo off REM First check to see if the script is running with elevated privileges. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config" REM If the previous command failed to write the temporary file, REM it means that we do not have permissions to write, and therefore REM do not have administrative privileges. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin REM <Your original batch commands go here> echo Running elevated… echo Setting Ethernet to static IP 192.168.5.185 netsh interface ip set address Ethernet static 192.168.5.185 255.255.255.0 192.168.5.1 1 netsh interface ip set dnsservers Ethernet source=dhcp echo Done. pause ```` ## VS code Tool SQLite3 Editor: view database file ![image](https://hackmd.io/_uploads/HkWYMd1hxe.png) Note: Backup link: https://marketplace.visualstudio.com/items?itemName=yy0931.vscode-sqlite3-editor ## Http download sequence: 1.Client sends an HTTP request to download a file. 2.Server continues sending TCP packets with the file content until the transfer is finished. 3.Server sends an HTTP 200 OK when finished. ![http_download_sequence](https://hackmd.io/_uploads/HyYYPEHcgx.png) ## Putty Putty Error: Unable to open connection to X.X.X.X Host does not exist ![image](https://hackmd.io/_uploads/rJqrWbHmxl.png) Solve: Command to putty folder ```` .\PuTTY.lnk -cleanup ```` ![image](https://hackmd.io/_uploads/BJ-6ebrmlx.png) ## Cppcheck --- - Link - https://github.com/danmar/cppcheck/releases 1. Analyze > Directory ![image](https://hackmd.io/_uploads/H1Lw1AsMxg.png) 2. choose your project folder ![image](https://hackmd.io/_uploads/H1_uJ0sGgl.png) 3. Result as below ![image](https://hackmd.io/_uploads/SyZFkCsMee.png) 4. Filter by toggle Result ![image](https://hackmd.io/_uploads/B1IYkCozxx.png) ## sequence ## dbus debug tool Environment: Linux Ubuntu Tools name: d-feet ``sudo apt install d-feet`` ![image](https://hackmd.io/_uploads/HJe8J_cm0yg.png) ## Network test Tool Clumsy https://jagt.github.io/clumsy/ ![image](https://hackmd.io/_uploads/HktX6DM01x.png) ## Memory map OS: Ubuntu 22.04.4 LTS Date:2024/07/16 Map as image:![slide2](https://hackmd.io/_uploads/HJJxrc4OR.jpg) Sample File Download: [Link](https://drive.google.com/file/d/1esqRUt_hEzYepkpoZEPbBxjRa72wmX6W/view?usp=drive_link) Steps: 1. Unzip Sample File 2. Terminal move into folder C ```` cd ~/test_func_life/c ```` 3. Make ```` make ```` 4. Run exe ```` ./memory_watcher ```` 5. Observe memory address ![real_run](https://hackmd.io/_uploads/ry1Z_cV_A.jpg) ## Notion ### Table reference Example: T2 reference T1 column ![Slide1](https://hackmd.io/_uploads/HykPoeKL0.jpg) 1. T2 add properties, choose "Relation", choose talbe "T1" 2. in T1 column choose row (ex:i) 3. add properties, choose "Rollup", Relation choose "T1", Property choose "FormulaTest" ![Slide2](https://hackmd.io/_uploads/S1_ecgYLR.jpg) 4. T2 add properties "Formula", reference should change to variable by: ```` sum(XXX) ```` ## Windows tools ### 磁碟分割Disk Shrink step5: size(MB) for new Disk ![image](https://hackmd.io/_uploads/BkpdH49ilx.png) ![image](https://hackmd.io/_uploads/SJDcFVcoxg.png) ### windows內建hash工具 ````shell C:\Users\tecra_mark2>certutil -hashfile "D:\FILE.zip" md5 ```` ### WSL ref: https://ithelp.ithome.com.tw/articles/10255920 1.Turn On Hyper-V ![wsl1](https://hackmd.io/_uploads/B1-_zxk7A.jpg) 2.PowerShell with Administrator ```` dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux wsl --set-default-version 2 wsl.exe --update ```` 3.Turn On sub-system ![wsl2](https://hackmd.io/_uploads/BkgVXgkXA.jpg) 4. ## Linux Net command ### DNS server inactive check status ````shell sudo systemctl status systemd-resolved ```` Restart Service ````shell sudo systemctl restart systemd-resolved ```` ## THSR-Robot 填入表單方式使用selenium ### 自動填單 https://jzchangmark.wordpress.com/2015/03/05/%E9%80%8F%E9%81%8E-selenium-%E6%93%8D%E4%BD%9C%E4%B8%8B%E6%8B%89%E5%BC%8F%E9%81%B8%E5%96%AE-select/ ### 圖片辨識 1.https://github.com/uranus4ever/Captcha-Crack 2.https://www.learncodewithmike.com/2021/08/python-selenium-bypass-captcha.html 3.使用gpt推薦的tesseract-ocr無法辨識有躁點的圖片(僅能辨識無躁點圖) 4.使用2captcha網站API #### 使用tesseract 解決方法: 1. 到 Github 下載 tesseract-ocr-w64-setup-v5.0.0-alpha.20200328.exe 來安裝Tesseract。 2. 記錄Tesseract安裝的路徑,預設路徑通常為 C:\Users\USER\AppData\Local\Tesseract-OCR。 C:\Program Files\Tesseract-OCR 3. 將Tesseract.exe路徑新增到程式碼中: pytesseract.pytesseract.tesseract_cmd = 'C:\Users\USER\AppData\Local\Tesseract-OCR\\tesseract.exe' ## WebParser ### Parser分類 1.request經由UserAgent 2.selenium瀏覽器仿真 ### 經由使用者代理,防止被網站拒絕 ````python from fake_useragent import UserAgent url_test = "https://www.pathofexile.com/shop/category/alternate-skill-effects" user_agent = UserAgent() r = requests.get(url=url_test, headers={ 'user-agent': user_agent.random }) ```` ## yt紀錄 https://www.dcard.tw/f/tech_job/p/254227388?cid=8320E052-A6B7-4CA8-8409-E63A4ABF7CC1 ## Line Token 當條件符合時,經由Line訊息通知用戶。 ## Line Webhook 根據 https://steam.oxxostudio.tw/category/python/example/line-webhook.html Webhook 指的是一個「網址」,透過伺服器建立 Webhook 網址後,有串接 Webhook 的位置就能使用 HTTP 的 POST 方法,向伺服器傳送或接收特定的資料。 使用 ngrok + 本機環境建立 Webhook ### 建立Line Channel 1.登入Line Developer,依網站輸入需求完成帳號設定。 2.點選Create a new provider ## 無對外IP時利器: ngrok 參考: https://medium.com/%E4%BC%81%E9%B5%9D%E4%B9%9F%E6%87%82%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/%E5%BF%AB%E9%80%9F%E8%AE%93%E5%A4%96%E7%B6%B2%E9%80%A3%E6%8E%A5%E6%9C%AC%E6%A9%9F%E7%9A%84%E5%88%A9%E5%99%A8-ngrok-ac92f792e1f0 我的筆記: https://plausible-tangerine-5fd.notion.site/ngrok-non-static-IP-forwarding-3abf20ac0be94288b5239a3e89c8a2bd?pvs=4 ### Linux背景執行ngrok取得URL方法 Linux背景執行ngrok 腳本如下 ````bash #!/bin/bash # Display current time echo "Current time: $(date)" # call ngrok to port tansport ngrok http 8080 --log=stdout > /tmp/ngrok.log sleep 3 cat /tmp/ngrok.log ```` 呼叫如下 ````shell nohup ./script_ngrok_server.sh & ```` 取得url方法 ````shell cat /tmp/ngrok.log ```` 尋找start tunnel那段的url ````text t=2024-01-31T08:12:44+0000 lvl=info msg="started tunnel" obj=tunnels name=command_line addr=http://localhost:8080 url=https://7239-2001-b400-e380-f5da-5ea4-a574-ea1-dfdc.ngrok-free.app ```` ## NTU-OOP ### 01_02_class generate practice ![image](https://hackmd.io/_uploads/Bk6WVpIFT.png) ![image](https://hackmd.io/_uploads/ryeWNa8F6.png) # Raspberry Pi related ## Raspberry Pi as DNS Server Device: Raspberry Pi 3B+ Net: Static IP ref:https://pimylifeup.com/raspberry-pi-vpn-server/ 1. Port Forward for your Raspberry Pi VPN Default Port : 1194 as UDP 2. Install OpenVPN ````bash sudo apt-get update -y curl -L https://install.pivpn.io | bash ```` Are you Using DHCP Reservation on your Router/DHCP Server? x x These are your current Network Settings: x x x x IP address: 192.168.3.12/24 x x Gateway: 192.168.3.1 lqqqqqqqqqqqqqqqqqqqqqqqqu Public IP or DNS tqqqqqqqqqqqqqqqqqqqqqqqqk x Will clients use a Public IP or DNS Name to connect to your server x x (press space to select)? x x x x (*) 111.184.133.63 Use this public IP 3. Setting up Open VPN User 4. ## 使用Raspberry Pi 3B+分享可上網Wifi AP ### Struct as below ![wifi_ap_struct](https://hackmd.io/_uploads/Sk039RFRT.jpg) #### 1.Install necessary packages: ```` sudo apt install hostapd dnsmasq ```` #### 2.Configure DHCP client for Ethernet: ```` sudo nano /etc/dhcpcd.conf ```` Add or modify the following lines to allow eth0 to obtain an IP address via DHCP: ```` interface eth0 hostname ```` #### 3.Configure DHCP server (dnsmasq): ```` sudo nano /etc/dnsmasq.conf ```` Add or modify the following lines to configure DHCP for the wireless network (wlan0): ```` interface=wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h ```` #### 4.Configure static IP for WiFi: ```` sudo nano /etc/dhcpcd.conf ```` Add the following lines to assign a static IP address to wlan0: ```` interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant ```` #### 5.Configure hostapd: ```` sudo nano /etc/hostapd/hostapd.conf ```` Add the following configuration: ```` interface=wlan0 driver=nl80211 ssid=YourAPName hw_mode=g channel=7 wmm_enabled=0 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=YourPassword wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCM ```` #### 6.Configure hostapd default file: ```` sudo nano /etc/default/hostapd ```` Find the line with #DAEMON_CONF="" and replace it with: ```` DAEMON_CONF="/etc/hostapd/hostapd.conf" ```` #### 7.Enable IPv4 forwarding: ```` sudo nano /etc/sysctl.conf ```` Uncomment the following line to enable IP forwarding: ```` net.ipv4.ip_forward=1 ```` Apply changes. ```` sudo sysctl -p ```` #### 8.Enable NAT (Network Address Translation): ```` sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" ```` #### 9.Configure iptables to load on boot: ```` sudo nano /etc/network/if-up.d/iptables ```` Add lines to the file. ```` #!/bin/sh iptables-restore < /etc/iptables.ipv4.nat ```` Save the setting. ```` sudo chmod +x /etc/network/if-up.d/iptables ```` #### 10.Restart services: ```` sudo systemctl restart networking sudo systemctl restart hostapd sudo systemctl restart dnsmasq ```` ## 使用Raspberry Pi 3B+架設DNS server ### Struct as below: ![image](https://hackmd.io/_uploads/rJ5H6WpiT.png) ### Result: from PC browser after connection ![dns_server_index](https://hackmd.io/_uploads/ryQWOYpja.png) ### ref: 1. https://micro.rohm.com/tw/deviceplus/how-tos/raspberrypi-guide/how-to-use-a-raspberry-pi-as-a-dns-server/ 2. http://www.intellamech.com/RaspberryPi-projects/rpi3_simple_wifi_ap.html 3. https://blog.gtwang.org/iot/raspberry-pi-install-nginx-lightweight-web-server/ ### **No.1 nginx with index.html** ref to RPi nginx index ### **No.2 DNS Server set** * install dnsmasq and set ````shell sudo apt install dnsmasq -y sudo nano /etc/dnsmasq.conf ```` * edit dnsmasq.conf Remove # ```` “#domain-needed” “#bogus-priv” “#no-resolv” ```` Add ```` server=8.8.8.8 server=8.8.4.4 address=/www.rpi3mark.com/192.168.5.1 ```` ### **No.3 WiFi AP mode** * install hostapd and set ````shell sudo apt install hostapd -y ```` * Configure wlan0 * edit dhcpcd.conf ```` sudo nano /etc/dhcpcd.conf ```` * add below: ```` denyinterfaces wlan0 ```` * edit interfaces ```` sudo nano /etc/network/interfaces ```` * wlan0 set as: ```` allow-hotplug wlan0 iface wlan0 inet static address 192.168.5.1 netmask 255.255.255.0 network 192.168.5.0 broadcast 192.168.5.255 ```` * Restart dhcpcd & Reload wlan0 ```` sudo service dhcpcd restart sudo ifdown wlan0; sudo ifup wlan0 ```` * Setup hostapd * edit hostapd.conf ```` sudo nano /etc/hostapd/hostapd.conf ```` * add below: ```` interface=wlan0 driver=nl80211 hw_mode=g channel=6 ieee80211n=1 wmm_enabled=1 ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] macaddr_acl=0 ignore_broadcast_ssid=0 # Use WPA2 auth_algs=1 wpa=2 wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP # Change these to your choice # This is the name of the network ssid=Pi3-AP-MarkYL # The network passphrase wpa_passphrase=00000000 ```` * edit default/hostapd.conf ```` sudo nano /etc/default/hostapd ```` * Replace #DAEMON_CONF="" with: ```` DAEMON_CONF="/etc/hostapd/hostapd.conf" ```` * Setup dnsmasq * edit dnsmasq.conf ```` sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo nano /etc/dnsmasq.conf ```` * add below: ```` interface=wlan0 # Use interface wlan0 listen-address=192.168.5.1 # Specify the address to listen on bind-interfaces # Bind to the interface server=8.8.8.8 # Use Google DNS domain-needed # Don't forward short names bogus-priv # Drop the non-routed address spaces. dhcp-range=192.168.5.50,192.168.5.150,12h # IP range and lease time ```` * Restart service ````shell sudo service hostapd start sudo service dnsmasq start sudo reboot ```` ### **No.4 Test** * PC search wifi named * ssid : Pi3-AP-MarkYL * password : 00000000 * Browser with url: http://www.rpi3mark.com/ would show index ## 使用Raspberry Pi 3B+架設串流 參考 https://blog.gtwang.org/iot/raspberry-pi-nginx-rtmp-server-live-streaming/ https://blog.csdn.net/k0307x1990y/article/details/127305689 #### 呼叫cam 原本為,遇到錯誤:WARNING: erroneous pipeline: no element "omxh264enc". ```` gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! queue ! videoconvert ! omxh264enc ! h264parse ! flvmux ! rtmpsink location='rtmp://localhost/rtmp/live live=1' ```` 修改成X ```` gst-launch-1.0 -vvv videotestsrc ! 'video/x-raw,framerate=30/1,format=UYVY' ! v4l2h264enc ! 'video/x-h264,level=(string)4' ! decodebin ! videoconvert ! fakesink ```` 修改成2 ```` gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! queue ! videoconvert ! v412h264enc ! h264parse ! flvmux ! rtmpsink location='rtmp://localhost/rtmp/live live=1' ```` 嘗試安裝:失敗 ```` sudo apt-get install gstreamer1.0-omx sudo apt-get install gstreamer1.0-omx-dbg ```` 查詢 ```` gst-inspect-1.0 | grep h264 gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! queue ! videoconvert ! omxh264enc ! h264parse ! flvmux ! rtmpsink location='rtmp://localhost/rtmp/live live=1' ```` 使用其他enc ```` sudo apt-get install gstreamer1.0-plugins-ugly gst-launch-1.0 -v v4l2src ! 'video/x-raw, width=640, height=480, framerate=30/1' ! queue ! videoconvert ! x264enc ! h264parse ! flvmux ! rtmpsink location='rtmp://localhost/rtmp/live live=1' ```` 安裝鏡頭驅動 ```` sudo apt-get install fswebcam ```` #### 測試鏡頭拍照 ```` fswebcam -r 640*480 cammer1.jpg fswebcam -S 10 -p YUYV 0103_4.jpg ```` * GD Error: gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: 拍出來一片漆黑的話: 需要加入 -p:palette format 為YUYV後正常 -S:跳過前面幾幀 #### 使用filezilla連上RPI取得檔案 sftp:172.20.10.9 pi 0000 暫先使用ffmpeg ```` sudo apt-get install ffmpeg ffmpeg -f video4linux2 -r 24 -i /dev/video0 -f flv rtmp://localhost:1935/rtmp/live ```` rtmp ```` rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; allow publish all; allow play all; exec ffmpeg -i rtmp://0.0.0.0/live/$name -filter:v scale=640:480 -c:v h264_omx -b:v 750k -c:a aac -b:a 128k -f flv rtmp://0.0.0.0/hls/$name_low; } application hls { live on; hls on; hls_path /tmp/hls; hls_fragment 3; hls_playlist_length 60; allow play all; } } } ```` #### 2024/01/04電腦使用VLC可觀看RPI直播: 1.RPI設定sudo nano nginx.conf ```` rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; allow publish all; allow play all; exec ffmpeg -f v4l2 -i /dev/video0 -c:v copy -c:a aac -b:a 128k -f flv rtmp://0.0.0.0/hls/st> } application hls { live on; hls on; hls_path /tmp/hls; hls_fragment 3; hls_playlist_length 60; allow play all; } } } ```` ```` sudo service nginx restart ```` 檢查 ```` netstat -tunlp | grep 1935 sudo netstat -anp |grep 80 ```` 2.RPI執行 ```` ffmpeg -i /dev/video0 -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://192.168.3.11/live/stream ```` 3.電腦使用VLC 媒體 > 開啟網路串流 > 點選"網路" > URL輸入:rtmp://192.168.3.11/live/stream 外網則是如下: rtmp://111.184.133.63/live/stream ffmpeg -i /dev/video0 -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://192.168.3.11/live/stream #### 待解項目 * 將ffmpeg...沒加上&與加上&於背景執行的結果不同:僅沒加上&可以成功推送到rtmp * #### 將ffmpeg指令於背景執行 #### 將RTMP轉換成http可讀取版本 ```bash wget https://nginx.org/download/nginx-1.22.1.tar.gz tar zxf nginx-1.22.1.tar.gz git clone https://github.com/winshining/nginx-http-flv-module.git cd nginx-1.22.1/ ./configure --prefix=/var/www --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module --without-http_proxy_module --add-module=/home/pi/nginx_src/nginx-http-flv-module ./configure --prefix=/usr/local/nginx --add-module=/home/pi/nginx_src/nginx-http-flv-module sudo make && sudo make install ```` 修改nginx.conf文件 執行nginx #execute nginx ```` cd /usr/local/nginx/sbin sudo ./nginx #ffmpeg push #ffmpeg -re -i /dev/video0 -c copy -f flv rtmp://172.20.10.9:1985/myapp/testv ffmpeg -i /dev/video0 -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 96k -r 25 -b:v 500k -s 640*480 -f flv rtmp://172.20.10.9:1985/myapp/testv ```` PC測試 VLS: rtmp://172.20.10.9:1985/myapp/testv Browser: http://172.20.10.9/live?port=1985&app=myapp&stream=testv http://172.20.10.9/flv?port=1985&app=myapp&stream=testv ## 掃描同網域IP (IP Scan) 2023/12/22 * 起因 找出許多未啟動的Raspberry Pi 3B+ 重新安裝SD卡內的OS,並且預先設定好WIFI,樹莓派開機後與PC一起在同一個網域,但需要知道樹莓派IP才有辦法SSH,故紀錄之。 1. 樹莓派連上wifi 2. PC連上wifi 3. PC掃描IP ````shell= ipconfig /all ###將下方指令170.20.10改成需要掃描的網域 for /L %i IN (1,1,254) DO ping -w 1 -n 1 172.20.10.%i arp -a ##try for /l %i in (1,1,254) do @ping 192.168.3.%i -w 10 -n 1 | find "TTL" ```` 掃描結果如下: ![image](https://hackmd.io/_uploads/Bk1BZHmw6.png) # Virtual Box Related ## No.1 sudo指令會出現 XXX is not in the sudoers file ### step1: 進入命令行模式 CTRL + ALT + F3 (需要返回桌面時CTRL + ALT + F1) ### step2: log in login: root password: XXXX ### step3: replace "markv" with your account name ```` adduser markv sudo ```` ### step4: reboot ```` reboot ```` ## No.2 安裝 Ubuntu 20.04 虛擬機,打不開 terminal ### step1: 進入命令行模式 CTRL + ALT + F3 (需要返回桌面時CTRL + ALT + F1) ### step2: log in loing: root password: XXXX ### step3: edit "locale" file nano /etc/default/locale #### 修改文件中以下兩處 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 ### step4: save and exit **ctrl + X**, then type "y", then press **enter**. ### step5: run setting in Terminal ```` sudo locale-gen --purge reboot # 重啟VirtualBox ```` ## No.3 Ubuntu20.04無法從外部複製貼上 1. 裝置>插入Guest Additions CD映像 ![copy_paste](https://hackmd.io/_uploads/B1ZDVFgwT.png) 2. 左側點選光碟圖案 3. 於資料夾空白處,點擊右鍵,選擇Open in Terminal ![右鍵貼上問題](https://hackmd.io/_uploads/Sy1LTBZ_a.png) 4. 輸入,等待安裝結束完成。 ```` ./autorun.sh ```` 5. Settings > Shared Clipboard ![vb_copy_paste](https://hackmd.io/_uploads/ByPcv7Igel.png) ### Virtual Box 空間擴大 ref: https://wuhsiublog.blogspot.com/2017/11/oracle-virtual-box-5x.html ``` .\VBoxManage.exe modifyhd "E:\vb7_u22\u22\u22.vdi" --resize 32768 ``` ### VirtualBox 畫面閃爍 * Setting > Display > Enable 3D Acceleration ![VB_screen_flash_issue](https://hackmd.io/_uploads/HkXN5C52p.png) ### Port Forwarding 1. 開啟Oracle VM VirtualBox Manager 2. 點選vb_u22 (若在執行中請先關閉),再點選Settings ![vb_settings](https://hackmd.io/_uploads/S1YKNniv6.png) 4. 點選Network > Adapter 1 > Advanced > PortForwarding ![vb_settings2](https://hackmd.io/_uploads/S1tWHhsw6.png) 5. 點選右上角增加Port,分別增加三項下圖紅框2 ![vb_settings3](https://hackmd.io/_uploads/HJ5782sP6.png) #### issue: Ethernet(enp0s8) keep connecting ref:https://www.cnblogs.com/wkyo/p/14961860.html check VirtualBox tool configuration as below pictures ![vb_tool_net_conf1](https://hackmd.io/_uploads/rkE--SDp6.png) ![vb_tool_net_conf2](https://hackmd.io/_uploads/H1Vb-HDpp.png) ### Samba 1. VB設定如下圖 ![1](https://hackmd.io/_uploads/SJgSJSWua.png) 2. 指令步驟 - 步驟1:安裝samba軟體 ```bash sudo apt install samba -y ``` - 步驟2:編輯smb.conf ```bash sudo nano /etc/samba/smb.conf ```` 增加一段[markv],將markv更改為您的名字 ````text #add below into .conf file [markv] comment = markv path = /home/markv/ browsable = yes guest ok = no writable = yes read only = no create mask = 0755 ```` - 步驟3新增一個samba使用者markv ```bash sudo smbpasswd -a markv ``` - 步驟4:重啟samba服務 ```bash sudo service smbd restart ``` - 步驟5:以windows10的案總管進入, 1. 在ubuntu Terminal輸入指令取得ubuntu的ip位址 ```bash ip addr ``` 2. 在windows下開啟檔案總管輸入“\\<ip位址>“,輸入帳號、密碼後即可進入 3. 建立路徑方法: 1. 打開”我的電腦” > 右鍵 > 點選”新增一個網路位置” : ![1](https://hackmd.io/_uploads/SJ1OjcJiT.png) 2. 下一步 > “選擇自訂網路位置” > 下一步 > 網際網路或網路位址(A) 輸入ip位置: 例如: \\\192.168.56.101\mark ,接著下一步 > 下一步 ![2](https://hackmd.io/_uploads/HymYsqko6.png) ![3](https://hackmd.io/_uploads/BJ8Ki9ks6.png) 3. 成功後我的電腦多了剛才新增的網路位置 ![4](https://hackmd.io/_uploads/r1oAi9ks6.png) Option: 刪除Windows網路磁碟認證&連線資訊 * Ref. [Link](https://laudaihe.medium.com/%E9%9B%9C%E8%A8%98-%E5%88%AA%E9%99%A4windows%E7%B6%B2%E8%B7%AF%E7%A3%81%E7%A2%9F%E8%AA%8D%E8%AD%89-%E9%80%A3%E7%B7%9A%E8%B3%87%E8%A8%8A-2e4bd495eefb) 1.刪除網路磁碟機 : cmd ```` net use /delete * ```` 2.刪除憑證 : 控制台 ![credential_remove](https://hackmd.io/_uploads/HJrXs5lEWe.png) ### Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host ![image](https://hackmd.io/_uploads/ryU-MSjJel.png) ### SSH server installation 虛擬機器,想要使用 SSH 協定連線至 VirtualBox 中的 Ubuntu 作業系統,在這邊還需要進一步使用指令 sudo service ssh status 來查詢 SSH 服務是否有在執行的狀態,如下圖所示可以看到回傳為檔案 not-found 的訊息,也就表示說此系統還未安裝好 OpenSSH Server 的套件,那接下來需要在系統上安裝會使用到的套件 10. 輸入指令來安裝 OpenSSH 套件 ````shell sudo apt-get install openssh-server -y ```` 11. 下指令 就可以查看到 SSH 服務啟動了 ````shell sudo service ssh status ```` ### Ubuntu22 SSH ref: https://snoopy30485.github.io/2018/06/30/VirtualBox%E4%BD%BF%E7%94%A8SSH%E9%80%A3%E7%B7%9A/ 1. 點選左上方檔案,選擇主機網路管理員 2. 可以看到裡面已經有一組 IP,選擇左上角建立可以新增 IP PS. 到本機 cmd 下指令 ```` shell ip addr ```` 可以看到預設就有 virtualbox 的網卡 3. VirtualBox app選擇機器點選設定 4. 先在要 SSH 連線的機器下指令 ip addr 查看 IP,可以看到 ip 是 10.0.2.15 5. 選擇網路打開進階選項,點選連接埠轉送 6. 點選右側 + 新增 7. 輸入自己想要的主機 IP,SSH 連線 port 是 22,客體 IP 就是剛剛機器的 IP ![image](https://hackmd.io/_uploads/BkryRAuua.png) 9. 在來回到虛擬機器,想要使用 SSH 協定連線至 VirtualBox 中的 Ubuntu 作業系統,在這邊還需要進一步使用指令 sudo service ssh status 來查詢 SSH 服務是否有在執行的狀態,如下圖所示可以看到回傳為檔案 not-found 的訊息,也就表示說此系統還未安裝好 OpenSSH Server 的套件,那接下來需要在系統上安裝會使用到的套件 10. 輸入指令來安裝 OpenSSH 套件 ````shell sudo apt-get install openssh-server -y ```` 11. 下指令 就可以查看到 SSH 服務啟動了 ````shell sudo service ssh status ```` ### SSH in VS code password-less authentication - ref: https://zhuanlan.zhihu.com/p/222452460 - Local(Win11) → Remote(Ubuntu22) - ![vscode_ssh](https://hackmd.io/_uploads/Sk23bcITa.jpg) 1. Win11 : VS code install “remote development” package 2. Authentication key 1. Local(Win11) : 1-1. generate public key in command window ```` ssh-keygen ```` ![keygen](https://hackmd.io/_uploads/BJ7Wu1lHA.jpg) 1-2. check "id_rsa.pub" had beed created ![keygen2](https://hackmd.io/_uploads/HJBhO1xHR.jpg) 1-3-1. install RemoteSSh in VS code ![vs_code_remote_config2](https://hackmd.io/_uploads/ByLCZCoD0.png) 1-3-2. edit VS code: Remote-SSH config file ![vs_code_remote_config](https://hackmd.io/_uploads/SkD2v1gBA.jpg) 1-4. add Path: example: C:\Users\tecra_mark2\.ssh\config ````bash Host VB_U22 HostName 10.61.10.71 User mark IdentityFile "C:\Users\tecra_mark2\.ssh\id_rsa" ```` ![keygen3config](https://hackmd.io/_uploads/rklDFylH0.jpg) 2. Remote(Ubuntu22) : 2-1. Copy contect in public key "id_rsa.pub" from Local(Win11) to Remote(Ubuntu22) ````bash cd ~/.ssh/ nano authorized_keys #paste "id_rsa.pub" content #save and exit ```` ![keygen4](https://hackmd.io/_uploads/rkpK6kgB0.jpg) Finish. 3. Option: Remove "known_hosts" in Host .ssh folder ![ssh_known_host](https://hackmd.io/_uploads/BJVC0laLkx.png) ### Ubuntu22 開啟啟動某服務1 ref:chatGPT,https://ithelp.ithome.com.tw/m/articles/10262738 0.create your script (ex:server.sh) ```` sudo touch /home/markv/server.sh chmod u+x /home/markv/server.sh sudo nano /home/markv/server.sh ```` change XXX to your password ```` #!/bin/bash echo "XXX" |sudo -S timedatectl set-timezone UTC echo "XXX" |sudo -S service mysql restart cd ~ source .profile cd ~/Downloads/steve java -jar target/steve.jar ```` 1.create service file (ex:server.service) change to your XXX.service ````bash sudo nano /etc/systemd/system/server.service ```` 2.edit edit service file ```` [Unit] Description=Start server.sh at boot [Service] Type=simple ExecStart=/home/markv/server.sh User=markv Group=markv WorkingDirectory=/home/markv/ Restart=always [Install] WantedBy=multi-user.target ```` 3.restart service ```` sudo systemctl daemon-reload sudo systemctl restart server.service ```` 4.check service ```` sudo systemctl status server.service ```` ### Ubuntu22 開啟啟動某服務2 ref: https://www.cnblogs.com/rainbow-tan/p/17346430.html 1. 開啟rc-local.service ````shell sudo nano /lib/systemd/system/rc-local.service ```` 增加以下資訊 ````shell [Install] WantedBy=multi-user.target Alias=rc-local.service ```` 2. 增加/etc/rc.local ````shell sudo touch /etc/rc.local sudo nano /etc/rc.local ```` 增加欲開機啟動的服務 ````shell #!/bin/sh sudo VBoxClient --clipboard sudo bash /home/markv/server.sh ```` 修改檔案權限 ````shell chmod u+x /etc/rc.local ```` 3. 開啟服務 ````shell systemctl enable rc-local.service ```` ### 直接增加HTTP download資料夾內檔案 1. 根據‣ 建立起apache的路徑 2. 修改權限 ```bash sudo chmod -R 777 \var\www\html\downloads ``` 3. 在我的電腦建立捷徑 - 我的電腦 > 右鍵 > 新增一個網路位置 - 下一步 > 下一步 >網際網路或網路位址輸入如下 (IP及使用者自行修改) >下一步 > 下一步 > 完成 ```bash \\192.168.253.129\markv22\var\www\html\downloads ``` ## vscode git Permission denied (publickey). ## Firewall setting ### Setting window firewall Default MQTT port 1883 is closed in windows 開始 > 防火牆與網路保護 > 進階設定 輸入規則 > 新增規則 > 選擇連接埠Port > TCP > 所有本機連接埠 > 8080 > 選擇 允許連線 > 私人 > 名稱:OCPP > 完成 輸入規則 > 同上 ## MQTT ### Method: 1.MQTT install : command #### MQTT Server ```` sudo apt update sudo apt upgrade -y sudo apt install mosquitto mosquitto-clients -y sudo systemctl enable mosquitto vim /etc/mosquitto/conf.d/test.conf ```` >allow_anonymous true listener 1883 ```` sudo systemctl status mosquitto sudo systemctl restart mosquitto ```` #### MQTT Client ```` sudo apt-get install build-essential libssl-dev cmake git sudo apt-get install libssl-dev sudo apt-get install uuid-dev sudo apt-get install cmake mkdir try_mqtt && cd try_mqtt git clone https://github.com/eclipse/paho.mqtt.cpp cd paho.mqtt.cpp cmake -Bbuild -H.-DPAHO_WITH_SSL=ON -DPAHO_BUILD_SAMPLES=ON cmake --build build/ --target install ```` Client ```` mosquitto_sub -h localhost -p 1883 -t "testchanel" -v ```` Server ```` mosquitto_pub -h localhost -p 1883 -t "testchanel" -m "Hello MQTT" ```` ### Method: 2.MQTT install : source #### MQTT Source install (instead of apt-get) 1. Source code download ```` wget http://mosquitto.org/files/source/mosquitto-2.0.15.tar.gz ```` 2. Unzip source code ```` tar -zxvf mosquitto-2.0.15.tar.gz cd mosquitto-2.0.15/ ```` 4. cJSON Download & Compile & install ```` git clone https://github.com/DaveGamble/cJSON.git cd cJSON make sudo make install ```` 6. Compile and install ```` cd .. make sudo make install ```` #### Eclipse Paho MQTT C++ library download & install 1. Install packages ```` sudo apt-get install -y build-essential gcc make cmake cmake-gui cmake-curses-gui libssl-dev doxygen graphviz ```` 2. (1)Building the Paho C library ```` git clone https://github.com/eclipse/paho.mqtt.c.git cd paho.mqtt.c git checkout v1.3.13 cmake -Bbuild -H. -DPAHO_ENABLE_TESTING=OFF -DPAHO_BUILD_STATIC=ON -DPAHO_WITH_SSL=ON -DPAHO_HIGH_PERFORMANCE=ON sudo cmake --build build/ --target install sudo ldconfig cmake -Bbuild -H. -DPAHO_ENABLE_TESTING=OFF -DPAHO_BUILD_STATIC=ON \ -DPAHO_WITH_SSL=ON -DPAHO_HIGH_PERFORMANCE=ON \ -DCMAKE_INSTALL_PREFIX=$HOME/install ```` 3. (2)Building the Paho C++ library ```` git clone https://github.com/eclipse/paho.mqtt.cpp cd paho.mqtt.cpp cmake -Bbuild -H. -DPAHO_WITH_MQTT_C=ON -DPAHO_BUILD_STATIC=ON -DPAHO_BUILD_DOCUMENTATION=ON -DPAHO_BUILD_SAMPLES=ON sudo cmake --build build/ --target install sudo ldconfig ```` 4. 5. Download code ```` git clone https://github.com/eclipse/paho.mqtt.cpp ```` #### MQTT C++ client code 3. client code ## cmake install in Ubuntu20 * Due to apt install cmake version is too old 1. Browser to https://cmake.org/download/ 2. Download tar file ex:cmake-3.28.1.tar.gz 3. Unzip ```` tar -zxvf cmake-3.28.1.tar.gz ```` 4. Check files ```` cd cmake-3.28.1 ./bootstrap ```` 5. Install ```` make -j8 sudo make install ```` 6. Check version ```` cmake --version ```` ## Remove Dual System(Win10 & Ubuntu) 1.Windows10於"開始"右鍵 > 磁碟管理 > 查看Ubuntu安裝![image](https://hackmd.io/_uploads/rkSoJ9nUp.png) 2.開始 > 搜尋PowerShell > 右鍵"管理員權限" 開啟 > ```` diskpart list DISK select DISK 2 ```` ## TLS Handshake flow 2023/12/15 ```sequence Note left of Client: Cipher Suites :N\nCompression Methods :N\nSignature algorithms :N\n... Client->Server: Client Hello(Handshake) Note right of Server: Cipher Suites: choose 1 in N\n Note right of Server: 1.Certificate\n2.Server Key Exchange\n3.Server Hello Done Server->Client: Server Hello Client->Server: Client Key Exchange Client->Server: Change Cipher Spec, Encrypted Handshake Message Server->Client: New Session Ticket Server->Client: Change Cipher Spec Server->Client: Encrypted Handshake Message(Handshake Done) ``` ## FTP-TLS flow 2023/12/13 ```sequence client->Server: non-TLS connect(port:21) Server->client: Note right of Server: Establish connection #Note right of Server: filezilla無回應點 client->Server: non-TLS Send: AUTH TLS Server->client: Note right of Server: Convert to mbedtls handshake flow\nExcept mbed_tls_connect() client->Server: mbedtls handshake(port:21) Server->client: mbedtls handshake client->Server: TLS Send: USER XXX Server->client: client->Server: TLS Send: PASS XXX Server->client: client->Server: TLS Send: PASV Server->client: TLS Send: data_port(port:XXXXX) client->Server: mbedtls handshake(port:XXXXX) Server->client: mbedtls handshake client->Server: mbedtls Start FTP downlaod Server->client: client->Server: ... Server->client: client->Server: Finish Server->client: ```