wireguard-on and off

/interface wireguard enable 0
/interface wireguard disable 0
#分別停用及啟用 後面數字 代表第幾條規則

/interface wireguard peer enable 0
/interface wireguard peer disable 0
#分別 peer 停用及啟用 後面數字 代表第幾條規則

——————————–
#https://blog.spaps.de/mikrotik-routeros-wireguard-dynamic-dns-endpoint-refresh/
或
#https://forum.mikrotik.com/viewtopic.php?t=182340
使用一個腳本來檢查對等端點地址是否仍然與 dns 名稱匹配,如果不匹配,則更新到 DNS 名稱的最新 ip 地址。
:local wgPeerComment
:local wgPeerDns

:set wgPeerComment "Peer #1 Comment"
:set wgPeerDns "dns.example.com"

:if ([interface wireguard peers get number=[find comment="$wgPeerComment"] value-name=endpoint-address] != [resolve $wgPeerDns]) do={
interface wireguard peers set number=[find comment="$wgPeerComment"] endpoint-address=[/resolve $wgPeerDns]
}

發表於 ros | 發表迴響

python-Decorator

https://www.youtube.com/watch?v=qc8hsxAK270&list=PL-g0fdC5RMboYEyt6QS2iLb_1m7QcgfHk&index=34

定義裝飾器
def 定義裝飾器(回呼函式):
def 內部函式():
#裝飾器函式內碼
回呼函式名稱()
return 內部函式名稱

使用裝飾器
@裝飾器名稱
def 函式名稱():
#函式程式碼
函式名稱() #呼叫帶有裝飾器名稱

範例:
def testDecorator(callback):
def innerFunc():
callback()
return innerFunc

@testDecorator
def decoratedFunc():
print("普通函式")

defcoratedFunc()

===============
#定義裝飾器
def myDeco(cb):
def run():
print("1.裝飾器中的程式碼")
cb(5) #這回呼函式,其實是被裝式的函式 test
return run
#使用裝飾器
@myDeco #先執行裝飾器內程式碼
def test(n):
print("2.普通函式程式碼", n)

test()

##callback 範例
print("=======================================")
print("callback")
def add(n1, n2, db):
db(n1 + n2)

def handle(result):
print("sum:" , result)

def handle1(result):
print("english sum1:" , result)

add(10, 23, handle)
add(10, 23, handle1)

handle(10)

發表於 python | 發表迴響

Python – call back

#callback
def test(arg):
#print(arg)
arg("hello") # function call
#arg(hello) to handle(data)

#定義一個回呼函式
def handle(data):
print(data)

test(handle)

def add(n1, n2, cb):
cb(n1+n2)

def handle1(result):
print("結果是: ", result )

def handle2(result):
print("English Result of Add is: ", result )

add(3, 4, handle1)
add(5, 6, handle2)

發表於 python | 發表迴響

python selenium-3

標籤ID
driver.find_element(By.ID,"條件")

標籤屬性搜尋 CSS
driver.find_element(By.CSS_SELECTOR,"[屬性名稱=屬性的值]")

模擬user input
element=driver.find_elemnet(search欄位,"條件")
element.send_keys("input key)

模擬 user inpurt key
element.send_keys(Keys.ENTER)
=======================================
#https://www.youtube.com/watch?v=tR558fQAHz8
#爬 leetcode
#https://leetcode.com/accounts/login/
#pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time #wating html loading

#chrom driver path https://chromedriver.chromium.org/downloads
options=Options()
options.chrome_executable_path="G:\我的雲端硬碟\PY\練習\chromdriver"

# Driver 物件
driver=webdriver.Chrome(options=options)

#連線到 LeetCode
driver.get("https://leetcode.com/accounts/login/")

#輸入帳號密碼, 按下 Enter
usernameInput=driver.find_element(By.ID, "id_login")
passwordInput=driver.find_element(By.ID, "id_password")

usernameInput.send_keys("myid")
passwordInput.send_keys("mypassword")

siginBtn=driver.find_element(By.ID, "signin_btn")
siginBtn.send_keys(Keys.ENTER)

#wait loading
time.sleep(5)

#連線到登入後才能取得Data
driver.get("https://leetcode.com/problemset/all/")
time.sleep(3)
statElement=driver.find_element(By.CSS_SELECTOR,"[data-difficulty=TOTAL]")
#print(statElement.text)
columns=statElement.text.split("\n") # List
print("已完成刷題數量: " + columns[1])

driver.close()

發表於 python | 發表迴響

python selenium-2

瀏覽器中執行程式
driver.execute_script("JavaScript Code")

捲動視窗到底部
dirver.execute_script("window.scrollTo(0,document.body.scrollHeight);)")

等待一陣子在捲動
imprt time
time.sleep("wait s")

==========================

#https://www.youtube.com/watch?v=ZOxIpMTgaXY
#https://www.linkedin.com/jobs/search?trk=guest_homepage-basic_guest_nav_menu_jobs&position=1&pageNum=0
#爬linkin
#pip install selenium

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time #wating html loading

#chrom driver path https://chromedriver.chromium.org/downloads
options=Options()
options.chrome_executable_path="G:\我的雲端硬碟\PY\練習\chromdriver"

# Driver 物件
driver=webdriver.Chrome(options=options)

#connect linkin
driver.get("https://www.linkedin.com/jobs/search?trk=guest_homepage-basic_guest_nav_menu_jobs&position=1&pageNum=0″)

n=0
while n<3:
#waiting
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
time.sleep(3) #wait 3s
n+=1

titlesTags=driver.find_elements(By.CLASS_NAME, "base-search-card__title")
for titleTag in titlesTags:
print(titleTag.text)

driver.close()

發表於 python | 發表迴響

python selenium-1

https://www.youtube.com/watch?v=ff5L6L5MTCw

取得標籤範例:
BY LINK
drive.find_element(By.LINK_TEXT,"要搜尋文字")

BY CLASS
drive.find_element(By.CLASS_NAME,"要搜尋文字")

操作標籤:
取得標籤內部文字:
element=drive.find_element(搜尋欄位,"要搜尋條件")
element.text

取得標籤屬性:
element=drive.find_element(搜尋欄位,"要搜尋條件")
element.get_attribute("屬性名稱")

模擬click:
element=drive.find_element(搜尋欄位,"要搜尋條件")
element.click().

=====================
#爬ppt stock
#pip install selenium
#https://www.ptt.cc/bbs/Stock/index.html
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

#chrom driver path https://chromedriver.chromium.org/downloads
options=Options()
options.chrome_executable_path="G:\我的雲端硬碟\PY\練習\chromdriver"

# Driver 物件
driver=webdriver.Chrome(options=options)

#connect ptt
driver.get("https://www.ptt.cc/bbs/Stock/index.html")
#print(driver.page_source) #get html source
tags=driver.find_elements(By.CLASS_NAME,"title")
for tag in tags:
print(tag.text)

#get up page use find_element
link=driver.find_element(By.LINK_TEXT, "‹ 上頁")
link.click()
tags=driver.find_elements(By.CLASS_NAME,"title")
for tag in tags:
print(tag.text)

driver.close()

發表於 python | 發表迴響

關閉 windows smb cache

cmd /WRITETHROUGH
關閉 smb 緩存

發表於 windows | 發表迴響

linux-bmon

https://linux.cn/article-8392-1.html

查看特定網卡 bmon -p enps0
查看每秒位元數 bmon -bp enps0
每5秒變更 bmon -r 5 -p enps0

bmon 有很多能提供网卡统计数据的输入模块,其中包括:

netlink – 使用 Netlink 协议从内核中收集网卡和流量控制统计信息。这是默认的输入模块。
proc – 从 /proc/net/dev 文件读取网卡统计信息。它被认为是传统界面,且提供了向后兼容性。它是 Netlink 接口不可用时的备用模块。
dummy – 这是用于调试和测试的可编程输入模块。
null – 停用数据收集。

bmon -i netlink:help
bmon -i proc -p enps0

bmon 也使用输出模块显示或者导出上面输入模块收集的统计数据,输出模块包括:

curses – 这是一个交互式的文本用户界面,它提供实时的网上估计以及每个属性的图形化表示。这是默认的输出模块。
ascii – 这是用于用户查看的简单可编程文本输出。它能显示网卡列表、详细计数以及图形到控制台。当 curses 库不可用时这是默认的备选输出模块。
format – 这是完全脚本化的输出模式,供其它程序使用 – 意味着我们可以在后面的脚本和程序中使用它的输出值进行分析。
null – 停用输出。

bmon -o curses:help

bmon -p enps0 -o ascii

bmon -p enp1s0 -o format

發表於 Network, linux | 發表迴響

Dock-comper-DNS SERVER

#dns
#https://www.youtube.com/watch?v=syzwLwE3Xq4&t=1290s

vim named.conf

#允許LAN
acl internal {
10.10.0.0/16;
10.11.0.0/16;
10.20.0.0/16;
};

options {
forwarders {
1.1.1.1;
};
allow-query { internal; }
}’

zone "demo.clcreative.de" in {
type master;
file "/etc/bind/demo-clcreative=de.zone";
};

#如果出現 ERROR: for bind9 can not start service bind9: driver failed programming external connectivitry on endpoint or starting userland proxy: listen tcp4 0.0.0.:53 bind:Aandress already in use
#vim /etc/systemd/resolved.conf
#DNSStubListener=no
systemctl restart systemd-resolved

vi demo-clcreative-de.zone
$TTL 2d

$ORIGIN demo.clcreative.de.

@ IN SOA ns.demo.clcreative.de. info.clcreative.de (
2022122800 ;serial
12h ;refresh
15m ;retry
3w ;expire
2h ;minimum ttl
)

IN NS ns.demo.clcreative.de.
ns IN A 10.20.3.4
;

srv-prod-1 IN 10.20.0.2
srv-prod-1 IN 10.20.0.3

發表於 未分類 | 已標籤 | 發表迴響

linux 使用crontab 開機後立刻執行

1.crontab -e
2.
@reboot sleep 60 ; /root/my-shell.sh
#開機60s後執行

發表於 未分類 | 已標籤 | 發表迴響