kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

Linux命令行截屏

ubuntu

1
sudo apt-get install scrot

centos

scrot0.8 https://github.com/dreamer/scrot

scrot0.8

http://packages.psychotic.ninja/7/base/x86_64/RPMS/giblib-1.2.4-22.el7.psychotic.x86_64.rpm

http://packages.psychotic.ninja/7/base/x86_64/RPMS/giblib-devel-1.2.4-22.el7.psychotic.x86_64.rpm

giblib-1.2.4-22.el7.psychotic.x86_64.rpm

giblib-devel-1.2.4-22.el7.psychotic.x86_64.rpm

1
2
3
4
5
6
7
8
9
yum install imlib2
yum install imlib2-devel

rpm -ivh giblib-1.2.4-22.el7.psychotic.x86_64.rpm
rpm -ivh giblib-devel-1.2.4-22.el7.psychotic.x86_64.rpm

$ ./configure
$ make
# make install

scrot https://github.com/resurrecting-open-source-projects/scrot

scrot

1
2
3
4
5
6
7
8
9
10
yum install automake
yum install autoconf
yum install autoconf-archive.noarch 
yum install libXtst-devel
yum install libXcomposite-devel

$ ./autogen.sh
$ ./configure
$ make
# make install

用Scrot截屏

1.截取整个桌面十分简单。只需运行Scrot命令,不需要任何参数,然后它会保存一张整个桌面的截屏,以(日期标记).png的文件形式保存在当前文件目录下。

1
$ scrot

你也可以指定保存目标文件夹和截图文件名。

1
$ scrot ~/Pictures/my_desktop.png

2.截取特定窗口或矩形区域

Scrot允许你在桌面选择一个特定的窗口或定义一个矩形区域来截图。使用下列命令来实现:

1
$ scrot -s

运行这个命令后,继续用你的鼠标单击任意窗口或画出一个矩形,它能够触发对选定窗口/区域的屏幕截取。(LCTT译注,还要使用鼠标,伐快乐)

有时候你选定的区域或窗口可能会被桌面的其它窗口部分遮挡。在这种情况下,你在截屏前需要一点时间来清理那个部分。那正是延迟截屏能够帮到你的,就像下面所描述的那样。

3.延迟截屏

延迟截取在各种情况下都很实用。就在截图前,你可能想要移动一下窗口,激活一下菜单,或是触发特定时间(如通知)等等。 使用“-d N”参数,我们可以将截屏进程延迟N秒。

1
$ scrot -s -d 5

4.调整截屏质量

你可以在1到100的范围内调整截取的图像质量(数字越大质量越高)。默认质量设置为75。

1
$ scrot -q 50

5.调整截屏尺寸

你可以在1到100的范围内调整截取的图像尺寸(数字越大尺寸越大)。减小截屏的尺寸到原图的10%:

1
$ scrot -t 10

6.将截取的截屏传递给其它命令

Scrot允许你发送保存的截屏图像给任意一个命令作为它们的输入。这个选项在你想对截屏图像做任意后期处理的时候十分实用。截屏的文件名/路径跟随于“$f”字符串之后。

1
$ scrot -e 'mv $f ~/screenshots'

gre

1. GRE介绍

GRE隧道是一种IP-over-IP的隧道,是通用路由封装协议,可以对某些网路层协议的数据报进行封装,使这些被封装的数据报能够在IPv4/IPv6 网络中传输。

Tunnel 是一个虚拟的点对点的连接,提供了一条通路使封装的数据报文能够在这个通路上传输,并且在一个Tunnel 的两端分别对数据报进行封装及解封装。一个X协议的报文要想穿越IP网络在Tunnel中传输,必须要经过加封装与解封装两个过程。

要在Linux上创建GRE隧道,需要ip_gre内核模块,它是GRE通过IPv4隧道的驱动程序。

2.

A 1.1.1.1, lo:0 10.1.2.3

B 2.2.2.2, lo:0 10.4.5.6

A 上面:

1
2
3
4
5
ifconfig lo:0 10.1.2.3/24 up
ip tunnel add gre1 mode gre remote 1.1.1.1 local 2.2.2.2 ttl 225 dev enp13s0
ip addr add 10.1.2.3/24 peer 10.4.5.6/24 dev gre1
ip link set dev gre1 up
ip route add 10.4.5.6/24 dev gre1

B 上面:

1
2
3
4
5
ifconfig lo:0 10.4.5.6/24 up
ip tunnel add gre1 mode gre remote 2.2.2.2 local 1.1.1.1 ttl 225 dev enp13s0
ip addr add 10.4.5.6/24 peer 10.1.2.3/24 dev gre1
ip link set dev gre1 up
ip route add 10.1.2.3/24 dev gre1

nethogs 监控Linux的每个进程流量

1
2
3
4
5
sudo apt-get install libncurses5-dev
sudo apt-get install libpcap0.8-dev

yum install ncurses libpcap
yum install ncurses-devel libpcap-devel

adjust & fix bug nethogs-0.8.1-kk.tar

orig: https://packages.ubuntu.com/source/xenial/nethogs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Nethogs命令介绍

nethogs -help
usage: nethogs [-V] [-h] [-b] [-d seconds] [-v mode] [-c count] [-t] [-p] [-s] [device [device [device ...]]]
-V : prints version.
-h : prints this help.
-b : bughunt mode - implies tracemode.
-d : delay for update refresh rate in seconds. default is 1.
-v : view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB). default is 0.
-c : number of updates. default is 0 (unlimited).
-t : tracemode.
-p : sniff in promiscious mode (not recommended).
-s : sort output by sent column.
-a : monitor all devices, even loopback/stopped ones.
device : device(s) to monitor. default is all interfaces up and running excluding loopback

When nethogs is running, press:
q: quit
s: sort by SENT traffic
r: sort by RECEIVE traffic
m: switch between total (KB, B, MB) and KB/s mode


参数介绍:
    -V : 显示版本信息,注意是大写字母V.
    -v:切换显示单位,默认是默认是KB/s(0表示 KB/s,1表示KB,2表示B,3表示MB)
    -c:检测次数(后面直接跟数字)
    -a:检测所有的设备
    -d : 延迟更新刷新速率,以秒为单位。默认值为 1.
    -t : 跟踪模式.
    -b : bug 狩猎模式 — — 意味着跟踪模式.
    -p : 混合模式(不推荐).
    device: 要监视的设备名称. 默认为 eth0

以下是NetHogs的一些交互命令(键盘快捷键)
    m : 修改单位
    r : 按流量排序
    s : 按发送流量排序
    q : 退出命令提示符