2018年8月30日 星期四
2018年8月28日 星期二
安裝 shadowsock server
Synology DSM6.21
#介紹
https://zh.wikipedia.org/wiki/Shadowsocks
#git位置 shadowsock python
https://github.com/dgkang/shadowsocks-python
1.先安裝 python2 or python3皆可
2.安裝 python套件包 pip (ubuntu:apt-get install python-pip)
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
https://bootstrap.pypa.io/
3.pip 安裝 shadowsocks
pip install shadowsocks
4.
vi /etc/shadowsocks.json
{
"local_address": "127.0.0.1",
"local_port":1080,
"port_password":{
"6655":"nguguest",
"8080":"nguguest"
},
"timeout":600,
"method":"aes-256-cfb",
"fast_open":false
}
其中
"port_password":{
"6655":"nguguest",
"8080":"nguguest"
},
是設定server port 對應的 password
這邊沒有設定serverIP 因為不需要
5.
*ssserver -c /etc/shadowsocks.json遇到error
RuntimeError: can not find library crypto
*遇到Exception: libcrypto(OpenSSL) not found
參考https://ningselect.com/2018/05/01/synologyshadowsocks
修改 註解掉以下紅色四行
sudo vi /usr/lib/python2.7/site-packages/shadowsocks/crypto/util.py
*
#介紹
https://zh.wikipedia.org/wiki/Shadowsocks
#git位置 shadowsock python
https://github.com/dgkang/shadowsocks-python
1.先安裝 python2 or python3皆可
2.安裝 python套件包 pip (ubuntu:apt-get install python-pip)
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
https://bootstrap.pypa.io/
3.pip 安裝 shadowsocks
pip install shadowsocks
4.
vi /etc/shadowsocks.json
{
"local_address": "127.0.0.1",
"local_port":1080,
"port_password":{
"6655":"nguguest",
"8080":"nguguest"
},
"timeout":600,
"method":"aes-256-cfb",
"fast_open":false
}
其中
"port_password":{
"6655":"nguguest",
"8080":"nguguest"
},
是設定server port 對應的 password
這邊沒有設定serverIP 因為不需要
5.
*ssserver -c /etc/shadowsocks.json遇到error
RuntimeError: can not find library crypto
自行修改/usr/lib/python2.7/ctypes/util.py
拿個發行版的來取代
*遇到Exception: libcrypto(OpenSSL) not found
參考https://ningselect.com/2018/05/01/synologyshadowsocks
修改 註解掉以下紅色四行
sudo vi /usr/lib/python2.7/site-packages/shadowsocks/crypto/util.py
56 for name in lib_names:
57 if os.name == "nt":
58 paths.extend(find_library_nt(name))
59 # else:
60 # path = ctypes.util.find_library(name)
61 # if path:
62 # paths.append(path)
*
2020 update
最近重裝遇到另一個新error
TypeError: find_library() takes exactly 1 argument (3 given)
sudo -i 後進入root即可
ssserver -c /etc/shadowsocks.json -d start
(我直接sudo 不能,應該是lib path 的問題,沒有繼續trace)
最近重裝遇到另一個新error
TypeError: find_library() takes exactly 1 argument (3 given)
File "/usr/lib/python2.7/site-packages/shadowsocks/crypto/openssl.py", line 41, in load_openssl
raise Exception('libcrypto(OpenSSL) not found')
Exception: libcrypto(OpenSSL) not found
sudo -i 後進入root即可
ssserver -c /etc/shadowsocks.json -d start
(我直接sudo 不能,應該是lib path 的問題,沒有繼續trace)
6.連線試試 後臺啟動
ssserver -c /etc/shadowsocks.json -d start
ssserver -c /etc/shadowsocks.json -d stop
ssserver -c /etc/shadowsocks.json -d restart
ssserver -c /etc/shadowsocks.json -d restart
2018年6月7日 星期四
svn 舊版安裝 (非 root)
ref.https://superuser.com/questions/929965/subversion-1-8-13-installation-without-root
http://www.cnblogs.com/xlmeng1988/p/3431321.html
http://www.cnblogs.com/xlmeng1988/p/3431321.html
cd $HOME
mkdir custom_installed
cd custom_installed
# Install apr
wget ftp://mirror.switch.ch/mirror/apache/dist//apr/apr-1.5.2.tar.gz
tar xvfz apr-1.5.2.tar.gz
cd apr-1.5.2
./configure —prefix=$HOME/custom_installed
make
make test
make install
cd ..
# Install apu
wget ftp://mirror.switch.ch/mirror/apache/dist//apr/apr-util-1.5.4.tar.gz
tar xvfz apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed
make
make test
make install
cd ..
wget http://apache.claz.org/subversion/subversion-1.8.13.tar.gz
tar xvfz subversion-1.8.13.tar.gz
cd subversion-1.8.13
wget http://www.sqlite.org/sqlite-amalgamation-3071501.zip
unzip sqlite-amalgamation-3071501.zip
mv sqlite-amalgamation-3071501 sqlite-amalgamation
./configure --prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed --with-apr-util=$HOME/custom_installed
make
make clean
./configure —prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed/bin/apr-1-config --with-apr-util=$HOME/custom_installed/bin/apu-1-config
2018年2月13日 星期二
ftrace
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace1/
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace2/
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace3/index.html
http://blog.csdn.net/scarecrow_byr/article/details/17741809
https://zhuanlan.zhihu.com/p/22130013
#先關閉tracing
echo 0 > tracing_on
#清除trace
echo 1 > trace
#啟用function_graph
echo function_graph > current_tracer
echo function1 funtion2 > set_graph_function
#開啟tracing
echo 1 > tracing_on
#不確定要不要開
echo 1 > /proc/sys/kernel/stack_tracer_enabled
echo 1 > /proc/sys/kernel/ftrace_enabled
執行function
#查看執行結果和所花費時間
cat trace
#關閉tracing
echo 0 > tracing_on
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace2/
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace3/index.html
http://blog.csdn.net/scarecrow_byr/article/details/17741809
https://zhuanlan.zhihu.com/p/22130013
#先關閉tracing
echo 0 > tracing_on
#清除trace
echo 1 > trace
#啟用function_graph
echo function_graph > current_tracer
echo function1 funtion2 > set_graph_function
#開啟tracing
echo 1 > tracing_on
#不確定要不要開
echo 1 > /proc/sys/kernel/stack_tracer_enabled
echo 1 > /proc/sys/kernel/ftrace_enabled
執行function
#查看執行結果和所花費時間
cat trace
#關閉tracing
echo 0 > tracing_on
2018年1月10日 星期三
linux kernel printk
https://www.kernel.org/doc/Documentation/printk-formats.txt
16進位e自動顯示0x
pintk( " %#x " ,hex);
常用
IPv4
%pI4 1.2.3.4
%pi4 001.002.003.004
%p[Ii]4[hnbl]
The additional ``h``, ``n``, ``b``, and ``l`` specifiers are used to specify
host, network, big or little endian order addresses respectively. Where
no specifier is provided the default network/big endian order is used.
16進位e自動顯示0x
pintk( " %#x " ,hex);
常用
int %d or %x
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx
s32 %d or %x
u32 %u or %x
s64 %lld or %llx
u64 %llu or %llx
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx
s32 %d or %x
u32 %u or %x
s64 %lld or %llx
u64 %llu or %llx
MAC
%pM 00:01:02:03:04:05
%pMF 00-01-02-03-04-05
%pMF 00-01-02-03-04-05
IPv4
%pI4 1.2.3.4
%pi4 001.002.003.004
%p[Ii]4[hnbl]
The additional ``h``, ``n``, ``b``, and ``l`` specifiers are used to specify
host, network, big or little endian order addresses respectively. Where
no specifier is provided the default network/big endian order is used.
IPv6
%pI6 0001:0002:0003:0004:0005:0006:0007:0008
%pi6 00010002000300040005000600070008
%pI6c 1:2:3:4:5:6:7:8
%pi6 00010002000300040005000600070008
%pI6c 1:2:3:4:5:6:7:8
2017年9月5日 星期二
IGMP multicast with vlc
windows server
1.Open cmd as administrator
2.route delete 224.0.0.0 mask 240.0.0.0
3.route add 224.0.0.0 mask 240.0.0.0 <IP of NIC>
VLC version 2.26
使用UDP 打流
2017年3月2日 星期四
C 語言中的函數指標
ref.http://ccckmit.wikidot.com/cp:main
C 語言中的函數指標
#include <stdio.h>
int add(int a, int b)
{
return a+b;
}
int mult(int a, int b)
{
return a*b;
}
int main()
{
int (*op)(int a, int b);
op = add;
printf("op(3,5)=%d\n", op(3,5));
op = mult;
printf("op(3,5)=%d\n", op(3,5));
}
C 語言中的函數指標
#include <stdio.h>
int add(int a, int b)
{
return a+b;
}
int mult(int a, int b)
{
return a*b;
}
int main()
{
int (*op)(int a, int b);
op = add;
printf("op(3,5)=%d\n", op(3,5));
op = mult;
printf("op(3,5)=%d\n", op(3,5));
}
函數指標型態 -- (function pointer type) 用typedef 將函數指標宣告成一種型態
#include <stdio.h>
typedef int(*OP)(int,int);
int add(int a, int b)
{
return a+b;
}
int mult(int a, int b)
{
return a*b;
}
int main()
{
OP op = add;
printf("op(3,5)=%d\n", op(3,5));
op = mult;
printf("op(3,5)=%d\n", op(3,5));
}
變動參數
#include <stdio.h>
#include <stdarg.h>
void printList(int head, ... )
{
va_list va;
va_start(va, head);
int i;
for(i=head ; i != -1; i=va_arg(va,int))
{
printf("%d ", i);
}
va_end(va);
}
int main( void )
{
printList(3, 7, 2, 5, 4, -1);
}
變動參數2
#include <stdio.h>
int debug(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
return vprintf(fmt, args);
}
int main()
{
debug("pi=%6.2f\n", 3.14159);
}
陳鍾誠 (2010年09月01日),(網頁標題) C 語言結構中的位元欄位,(網站標題) 陳鍾誠的網站,取自 http://ccckmit.wikidot.com/cp:structbits ,網頁修改第 5 版。
2017年2月28日 星期二
printf sprintf snprintf asprintf / fgets gets scanf sscanf 表示式
http://edisonx.pixnet.net/blog/post/35305668-%5Bc%5D-printf-%E5%BC%95%E6%95%B8%E8%AA%AA%E6%98%8E
fgetc,fputc,fgets,fputs,fscanf,fprintf,fread,fwrite
*scanf/gets/fgets
scanf : 不安全 若buff 比讀入的還小的話會造成溢位
https://sites.google.com/site/9braised/fan-si/c1
http://squall.cs.ntou.edu.tw/cprog/practices/scanfCommonTraps.pdf
特性:
接下來請注意需要完全了解 scanf() 每一個控制命令 scanf() 所做的動作, 例
*如 %s是
"跳過0或多個 white space, 由鍵盤緩衝區裡讀取連續不是 whitespace 的字元"
, 所謂 white space 包括 空格, '\t',和 '\n' 三個字元
*又例如 %c是
"不跳過任何字元, 直接由鍵盤緩衝區裡讀取單一一個字元"
* %d 是
"跳過所有 white space, 由鍵盤緩衝區裡讀取連續 0~9 之間的十進位數字, 轉換為二進位"
如果除了 white space 之外只看到不是 0~9 的字元,scanf("%d",&x) 回傳 0
(注意是回傳 0 代表這個命令沒有成功, x 的數值不變)
gets : 同樣不安全 會一直讀到'\n' 為止且將'\n'自動轉為'\0'丟進buff
,若buff 不夠大,和scanf 有同樣的問題
fgets(str, sizeof(str), stdin);
fgetc,fputc,fgets,fputs,fscanf,fprintf,fread,fwrite
#include <stdio.h>
int main()
{
printf ("Characters: %c %c \n", 'a', 65);
printf ("Decimals: %d %ld\n", 1977, 650000L);
printf ("Preceding with blanks: %10d \n", 1977);
printf ("Preceding with zeros: %010d \n", 1977);
printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
printf ("Width trick: %*d \n", 5, 10);
printf ("%s \n", "A string");
return 0;
}
Characters: a A
Decimals: 1977 650000
Preceding with blanks: 1977
Preceding with zeros: 0000001977
Some different radixes: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick: 10
A string
http://ccckmit.wikidot.com/cp:sscanf
#include <stdio.h>
int main() {
char name[20], tel[50], field[20], areaCode[20], code[20];
int age;
sscanf("name:john age:40 tel:082-313530", "%s", name);
printf("%s\n", name);
sscanf("name:john age:40 tel:082-313530", "%8s", name);
printf("%s\n", name);
sscanf("name:john age:40 tel:082-313530", "%[^:]", name);
printf("%s\n", name);
sscanf("name:john age:40 tel:082-313530", "%[^:]:%s", field, name);
printf("%s %s\n", field, name);
sscanf("name:john age:40 tel:082-313530", "name:%s age:%d tel:%s", name, &age, tel);
printf("%s %d %s\n", name, age, tel);
sscanf("name:john age:40 tel:082-313530", "%*[^:]:%s %*[^:]:%d %*[^:]:%s", name, &age, tel);
printf("%s %d %s\n", name, age, tel);
char protocol[10], site[50], path[50];
sscanf("http://ccckmit.wikidot.com/cp/list/hello.txt",
"%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
protocol, site, path);
printf("protocol=%s site=%s path=%s\n", protocol, site, path);
return 1;
}
其編譯執行結果如下所示。
D:\oc>gcc sscanf.c -o sscanf
D:\oc>sscanf
name:john
name:joh
name
name john
john 40 082-313530
john 40 082-313530
protocol=http site=ccckmit.wikidot.com path=cp/list/hello.txt
%s 可以用%[] 來表示的更精確
^ 表示非的意思
讀到換行符號即停止(換行符並不會從緩衝區讀出)
ex. %[^\n]
*代表忽略相關病讀出緩衝區
用 snprintf / asprintf 取代不安全的 sprintf*scanf/gets/fgets
scanf : 不安全 若buff 比讀入的還小的話會造成溢位
https://sites.google.com/site/9braised/fan-si/c1
http://squall.cs.ntou.edu.tw/cprog/practices/scanfCommonTraps.pdf
特性:
接下來請注意需要完全了解 scanf() 每一個控制命令 scanf() 所做的動作, 例
*如 %s是
"跳過0或多個 white space, 由鍵盤緩衝區裡讀取連續不是 whitespace 的字元"
, 所謂 white space 包括 空格, '\t',和 '\n' 三個字元
*又例如 %c是
"不跳過任何字元, 直接由鍵盤緩衝區裡讀取單一一個字元"
* %d 是
"跳過所有 white space, 由鍵盤緩衝區裡讀取連續 0~9 之間的十進位數字, 轉換為二進位"
如果除了 white space 之外只看到不是 0~9 的字元,scanf("%d",&x) 回傳 0
(注意是回傳 0 代表這個命令沒有成功, x 的數值不變)
gets : 同樣不安全 會一直讀到'\n' 為止且將'\n'自動轉為'\0'丟進buff
,若buff 不夠大,和scanf 有同樣的問題
fgets(str, sizeof(str), stdin);
較安全,因為有限制大小len,但是很是有許多不足的地方
1.當資料不足時fgets 會讀入換行資訊
2.當資料被len限制而截斷時,stdin 會留下剩下殘存的資訊導致下次讀入錯誤
2017年2月8日 星期三
2017年1月25日 星期三
linux 資料流重導向 (redirecte) stderr stdout
ref.鳥哥
ref.http://dywang.csie.cyut.edu.tw/dywang/linuxProgram/node20.html
資料流重導向
標準輸入(stdin) :代碼為 0 ,使用 < 或 << ;標準輸出(stdout):代碼為 1 ,使用 > 或 >> ;
標準錯誤輸出(stderr):代碼為 2 ,使用 2> 或 2>> ;
>> 為 append
> 為覆寫
1> :是將正確的資料輸出到指定的地方去
2> :是將錯誤的資料輸出到指定的地方去
若只下> 則預設等義>1
將資料輸出到不同的地方去呢?可以這麼寫:
find /home -name testing > list_right 2> list_error
將錯誤的資訊丟掉!
find /home -name testing > list_right 2> /dev/null
find /home -name testing > list 2> list <==錯誤寫法
find /home -name testing > list 2>&1 <==正確寫法
or
find /var -name run &>file
請特別留意這一點呢!同時寫入同一個檔案需要使用 2>&1 才對呦!
(這邊我的理解為 把 stderr導向stdout 的address 2>&1) 如此一來 stderr 就變為stdout了
方便的make linux
alias mkl='make linux vmimg 2>&1 | grep -i "error:\|correct"'
連續命令
指令間以分號( ; )隔開:連續執行指令。[root@linux ~]# sync; sync; shutdown -h now
指令間以 && 隔開:前面指令執行結果正確,就接著執行後續的指令,否則就略過。
[root@linux ~]# ls /tmp && touch /tmp/testingagin
## 目錄/tmp存在,所以/tmp/testingagin會被建立。
[root@linux ~]# ls /csie && touch /csie/test
## 目錄/csie不存在,所以touch /csie/test不會被執行。
指令間以 || 隔開:前一個指令有錯誤時,後面的指令才被執行。
[root@linux ~]# ls /tmp/csieing || touch /tmp/csieing
訂閱:
文章 (Atom)