2026年5月21日 星期四

單行 PowerShell 批次刪除現有排程

  • 執行以下指令,這會自動尋找所有以 OneDrive 開頭的排程工作(包含 Reporting 和 Update),並強制解除註冊(刪除),過程中不會跳出確認提示:
Get-ScheduledTask -TaskName "OneDrive*" | Unregister-ScheduledTask -Confirm:$false
  • 查看相關名稱的排程
Get-ScheduledTask -TaskName "OneDrive*"

關閉 Windows Defender

透過本地群組原則徹底停用(最乾淨)

這個方法可以確保 Defender 在重啟電腦後也不會自動復活。

  1. 按下 Win + R 鍵,輸入 gpedit.msc 並按確定,打開「本地群組原則編輯器」。
  2. 依序點開左側資料夾:
    電腦組態系統管理範本Windows 元件Windows Defender 防毒軟體(或寫為 Endpoint Protection)。
  3. 在右側視窗中,找到 「關閉 Windows Defender 防毒軟體」(Turn off Windows Defender Antivirus)。
  4. 連點兩下打開它,將狀態改為 「已啟用」(Enabled)。
  5. 點擊確定後,重新啟動伺服器。

2026年4月29日 星期三

2026年4月28日 星期二

nextcloud 使用 command line 進行版本更新

# 環境 

  • FreeBSD 14.3
  • PHP 8.4.18


# 安裝 pkg

> pkg install php82-phar

> service restart php_fpm


# 更新指令

> cd /nextcloud

> sudo -u www php updater/updater.phar

> sudo -u www php occ upgrade


# 檢查系統狀態

> sudo -u www php occ status

2026年3月11日 星期三

使用ping同時在螢幕顯示並將結果寫入檔案

  • powershell

ping -t 8.8.8.8 | ForEach-Object { "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $_" } | Tee-Object -FilePath "ping_log.txt"


2025年3月6日 星期四

ubuntu 查看 listen port

說明

  • 在不額外安裝netstat下,可以使用以下指令查看 LISTEN 的 port


查看ipv4


> ss -nlt4


查看ipv6


> ss -nlt6


同時查看ipv4 及 ipv6


> ss -nlt

2024年1月23日 星期二

librenms on Ubuntu 22.04 安裝手冊

ubuntu22.04 with php8.1 with nginx 安裝過程

參考文件

https://docs.librenms.org/Installation/Install-LibreNMS/

安裝package

sudo apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip whois traceroute

新增 librenms user

sudo useradd librenms -d /home/librenms -M -r -s “$(which bash)”

下載 librenms from git

cd /home

sudo git clone https://github.com/librenms/librenms.git

設定權限

sudo chown -R librenms:librenms /home/librenms

sudo chmod 771 /home/librenms

sudo setfacl -d -m g::rwx /home/librenms/rrd /home/librenms/logs /home/librenms/bootstrap/cache/ /home/librenms/storage/

sudo setfacl -R -m g::rwx /home/librenms/rrd /home/librenms/logs /home/librenms/bootstrap/cache/ /home/librenms/storage/

安裝 php 相依

sudo su - librenms

./scripts/composer_wrapper.php install —no-dev

exit

設定時區

sudo vi /etc/php/8.1/fpm/php.ini
sudo vi /etc/php/8.1/cli/php.ini

date.timezone = Asia/Taipei

sudo timedatectl set-timezone Asia/Taipei

設定MariaDB

sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

在[mysqld]下一行加入以下兩行

innodb_file_per_table=1
lower_case_table_names=0

sudo systemctl enable mariadb

sudo systemctl restart mariadb

sudo mysql_secure_installation

sudo mysql -u root

輸入以下SQL Command

CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY '[yourpassword]';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit

設定 php-fpm

sudo cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/librenms.conf

sudo vi /etc/php/8.1/fpm/pool.d/librenms.conf

[www]改成[librenms]

[librenms]
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock

設定 web server

sudo vi /etc/nginx/conf.d/librenms.conf

server {
 listen      80;
 server_name [yourdomain or ip];
 root        /home/librenms/html;
 index       index.php;

 charset utf-8;
 gzip on;
 gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
 location / {
  try_files $uri $uri/ /index.php?$query_string;
 }
 location ~ [^/]\.php(/|$) {
  fastcgi_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}

sudo rm /etc/nginx/sites-enabled/default

sudo systemctl restart nginx

sudo systemctl restart php8.1-fpm

設定lnms

sudo ln -s /home/librenms/lnms /usr/bin/lnms

sudo cp /home/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

設定 snmpd

sudo cp /home/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

sudo vi /etc/snmp/snmpd.conf

找到 RANDOMSTRINGGOESHERE 改成 public(或自已想要的)

sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro

sudo chmod +x /usr/bin/distro

sudo systemctl enable snmpd

sudo systemctl restart snmpd

設定 cronjob

sudo cp /home/librenms/dist/librenms.cron /etc/cron.d/librenms

sudo vi /etc/cron.d/librenms

將所有的路徑裡的資料夾opt改成home

設定scheduler

sudo cp /home/librenms/dist/librenms-scheduler.service /home/librenms/dist/librenms-scheduler.timer /etc/systemd/system/

sudo systemctl enable librenms-scheduler.timer

sudo systemctl start librenms-scheduler.timer

sudo vi /etc/systemd/system/librenms-scheduler.service

將所有的路徑裡的資料夾opt改成home

設定logrotate

sudo cp /home/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

匯入資料庫

sudo vi /home/librenms/.env

DB_HOST= localhost
DB_DATABASE= librenms
DB_USERNAME= librenms
DB_PASSWORD= [yourpassword]

sudo su - librenms

lnms migrate

php artisan key:generate

php artisan config:clear

php artisan config:cache

exit

web config

http://[yourdomain_or_ip]/

  • 建立管理員帳號

修改config.php權限

sudo chown librenms:librenms /home/librenms/config.php

驗證設定(或問題排除)

sudo su - librenms

cd /home/librenms

./validate.php

2023年8月3日 星期四

windows 設定 ntp 校時

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" -Name SpecialPollInterval -Value 3600

w32tm /unregister

w32tm /register

net start w32time

w32tm /config /manualpeerlist:"time.stdtime.gov.tw" /syncfromflags:manual /update

w32tm /resync

w32tm /query /status

2023年5月9日 星期二

javascript檢查瀏覽器

輸出瀏覽器資訊

document.getElementById("showbrowser").innerHTML = navigator.userAgent;

 <div id='showbrowser'></div>


確認各家瀏覽器

var isChrome = (navigator.userAgent.indexOf("Chrome") > -1) && (navigator.userAgent.indexOf("Safari") > -1);

var isIOSChrome = navigator.userAgent.indexOf("CriOS") > -1;

var isAndroidChrome = (navigator.userAgent.indexOf("Android") > -1) && (navigator.userAgent.indexOf("Chrome") > -1) && (navigator.userAgent.indexOf("Safari") > -1);

var isMacOSSafari = (navigator.userAgent.indexOf("Macintosh") > -1) && (navigator.userAgent.indexOf("Safari") > -1);

var isiPhoneSafari = (navigator.userAgent.indexOf("iPhone") > -1) && (navigator.userAgent.indexOf("Safari") > -1);

var isEdge = (navigator.userAgent.indexOf("Chrome") > -1) && (navigator.userAgent.indexOf("Safari") > -1) && (navigator.userAgent.indexOf("Edg") > -1);

var isFirefox = navigator.userAgent.indexOf("Firefox") > -1;


2023年4月21日 星期五

C# 抓取螢幕縮放比例


using Microsoft.Win32;

public static int DefaultscalingFactor = 96;
public static int scalingFactor = 0;

//取得目前的數值
var reg_url = "Control Panel\\Desktop\\WindowMetrics";
scalingFactor = int.Parse(Registry.CurrentUser.OpenSubKey(reg_url).GetValue("AppliedDPI").ToString());

//螢幕縮放比例 
scale = scalingFactor / DefaultscalingFactor;

2022年9月6日 星期二

windows 10 版本更新

 安裝了windows 10 20H2,怎麼按windows update都不會出現21H2的更新,所以上網找了一下解法。


到以下微軟網站下載Windwos10更新小幫手,然後執行更新即可

https://www.microsoft.com/zh-tw/software-download/windows10

2022年9月5日 星期一

使用powershell修改檔案修改日期

之前在同步nextcloud時,發現有些檔案沒有修改日期

在command line下看時間都是1970/1/1,導致資料同步失敗

後來發現,只要檔案有更新,就會恢復同步的功能

所以研究了powershell,將所有檔案(包含子資料夾)的修改日期為1970/1/1的列出

然後將現在時間寫入lastwritetime欄位。


以下為powershell程式碼


# 取得檔案清單

$list = get-childitem -recurse -path "D:\NextCloud" | where-object {$_.LastWriteTime.Year -eq "1970"} | %{$_.FullName}


#變更修改日期

foreach($file in $list){(get-item $file).LastWriteTime =(get-date)}


2022年6月10日 星期五

OpenVAS on Ubuntu 20.04

# 更新系統

> sudo apt update

> sudo apt upgrade

> sudo apt dist-upgrade


# 抓取script

> wget https://raw.githubusercontent.com/yu210148/gvm_install/master/install_gvm.sh

> chmod +x install_gvm.sh


# 執行script

> sudo ./install_gvm.sh -v 21 -a -u

2021年7月22日 星期四

chatterbot 1.0.8 安裝紀錄

建立conda環境

> conda create --name chatterbot python=3.6

啟動環境

> conda activate chatterbot


安裝chatterbot及語料庫

> pip install chatterbot

> pip install chatterbot_corpus


安裝spacy

* 沒有安裝的話,執行範例的時候會出現錯誤

> pip install spacy==2.1.8

> python -m spacy download en


範例

from chatterbot import ChatBot

from chatterbot.trainers import ListTrainer

 

# Create a new chat bot named Charlie

chatbot = ChatBot('Charlie')

 

trainer = ListTrainer(chatbot)

 

trainer.train([

    "Hi, can I help you?",

    "Sure, I'd like to book a flight to Iceland.",

    "Your flight has been booked."

])

 

# Get a response to the input text 'I would like to book a flight.'

response = chatbot.get_response('I would like to book a flight.')

 

print(response)


參考網站:https://chatterbot.readthedocs.io/en/stable/examples.html

2020年11月12日 星期四

修正cisco switch ssh無法連線問題

指令

switch#conf t

switch#crypto key zeroize

switch#crypto key generate rsa general-keys modulus 2048

switch#end

switch#wr


連線時出現的錯誤訊息

Unable to negotiate with 192.168.0.1 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 


修改後的連線方式

ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 -c aes256-cbc user@192.168.0.1

2020年10月26日 星期一

OpenVAS on CentOS 8

參考網站

https://www.libellux.com/openvas/#install-openvas-20-08-centos


 == 更新 CentOS ==

server@centos:~$ sudo yum -y update


== 關閉root可以登入ssh ==

server@centos:~$ sudo nano /etc/ssh/sshd_config

PermitRootLogin no

server@centos:~$ sudo systemctl restart sshd.service

server@centos:~$ sudo yum update

server@centos:~$ sudo nano /etc/ssh/sshd_config

PermitRootLogin no

server@centos:~$ sudo systemctl restart sshd.service

server@centos:~$ sudo yum update


== 查看SELinux狀態 ==

server@centos:~$ sudo sestatus

SELinux status:                 enabled


== 關閉SELinux ==

server@centos:~$ sudo setenforce 0

server@centos:~$ sudo nano /etc/selinux/config

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disabled

 

== 重新開機 ==

server@centos:~$ sudo shutdown -r now


== 再次確認SELinux狀態 ==

server@centos:~$ sudo sestatus

SELinux status:                 disabled


== 安裝 wget ==

server@centos:~$ sudo yum install wget


== download the Atomicorp installer ==

server@centos:~$ wget -q -O - https://updates.atomicorp.com/installers/atomic | sudo sh

For supported software packages please contact us at: 

  sales@atomicorp.com

Do you agree to these terms? (yes/no) [Default: yes] yes

Enable repo by default? (yes/no) [Default: yes]: yes


== Enable PowerTools and install extra packages ==

server@centos:~$ sudo yum config-manager --set-enabled PowerTools

server@centos:~$ sudo yum install epel-release


== 安裝 gvm ==

server@centos:~$ sudo yum install gvm


== 更新及設定admin密碼(這個跑很久) ==

server@centos:~$ sudo gvm-setup


== 進入網站 ==

https://127.0.0.1/

https://ipv4/

https://[ipv6]/

2020年10月6日 星期二

Chrome 啟動參數

路徑

"C:\Users\Duck\AppData\Local\Google\Chrome\Application\chrome.exe" 

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"


參數
--proxy-server=myproxy:3128設定proxy
--incognito無痕模式
--kiosk啟動時全螢幕(F11無效)
--disable-pinch禁止兩指縮放螢幕
--overscroll-history-navigation=0禁止螢幕滑動
--disable-javascript禁止javascript
--disable-ipv6禁止ipv6
--disable-desktop-notifications禁止提示
--disable-audio禁止audio

2020年8月27日 星期四

VirtualBox cli 控制命令

 啟動VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm {name / uuid}


背景啟動VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm {name / uuid} --type headless


列出所有的VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list vms


列出所有執行中的VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" list runningvms


暫停VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {name / uuid} pause


啟動暫停的VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {name / uuid} resume


重設VM

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {name / uuid} reset


強制關機

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {name / uuid} poweroff


關機

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm {name / uuid} acpipowerbutton


查看VM裡的IP設定 (需安裝agent)

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" guestproperty get {name / uuid} "/VirtualBox/GuestInfo/Net/0/V4/IP"