2016年10月25日星期二

交换机端口安全最佳实践配置

sticky 与 aging 同时配置之后,aging不会生效,因为他们不能同时使用
sticky 的配置是学习mac地址后与端口绑定(而且是永久绑定,除非手动清除),这样同一台设备再接其他交换机的端口时,就会进入err-disable。

以下配置,不会在端口下保存MAC地址,也就是说,一部电脑插上交换机的f0/3口后,去插f0/6口是不会出现err-disable状态的。

XYJ-C2960_11#show port-security int f0/10 | in Aging
Aging Time                 : 1 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled

XYJ-C2960_11(config)#int f0/10
XYJ-C2960_11(config-if)#switchport port-security
XYJ-C2960_11(config-if)#switchport port-security violation shutdown
XYJ-C2960_11(config-if)#switchport port-security maximum 1

XYJ-C2960_11(config-if)#do show port-s int f0/10 | in Aging
Aging Time                 : 1 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Enabled

以下三条命令基本上测不出来什么实际效果,虽然有细微不同,所以有与无均可。
switchport port-security aging type inactivity | absolute
switchport port-security aging time 1
switchport port-security aging static
要说出确切不同,就是没有配置aging,那么mac地址被记录一次后就再也不过期了,让后如果max为3,就是说接了三台pc后,第四台就会触发errdisable。
如果说aging配置了,并且为3分钟,那么接了三台后,第四台不会触发,因为没5分钟后自动清除该表表项
XYJ-C2960_9#show port-security interface f0/23 add
               Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan    Mac Address       Type                          Ports   Remaining Age
                                                                   (mins)    
----    -----------       ----                          -----   -------------
  11    000c.29e1.0542    SecureDynamic                 Fa0/23       -
  11    6400.6a95.9017    SecureDynamic                 Fa0/23       -
-----------------------------------------------------------------------------
Total Addresses: 2

XYJ-C2960_9#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
XYJ-C2960_9(config)#int f0/23
XYJ-C2960_9(config-if)#switchport port-security aging time 5
XYJ-C2960_9(config-if)#end
XYJ-C2960_9#show port-security interface f0/23 ad
               Secure Mac Address Table
-----------------------------------------------------------------------------
Vlan    Mac Address       Type                          Ports   Remaining Age
                                                                   (mins)    
----    -----------       ----                          -----   -------------
  11    000c.29e1.0542    SecureDynamic                 Fa0/23       5
  11    6400.6a95.9017    SecureDynamic                 Fa0/23       5
-----------------------------------------------------------------------------
Total Addresses: 2

因为是使用shutdown的惩罚,所以要启用自动恢复,才可以避免手动操作的麻烦
XYJ-C2960_11(config)#errdisable recovery cause psecure-violation
XYJ-C2960_11(config)#errdisable recovery interval 30
XYJ-C2960_11#show errdisable recovery 
ErrDisable Reason            Timer Status
-----------------            --------------
arp-inspection               Disabled
bpduguard                    Disabled
channel-misconfig (STP)      Disabled
dhcp-rate-limit              Disabled
dtp-flap                     Disabled
gbic-invalid                 Disabled
inline-power                 Disabled
link-flap                    Disabled
mac-limit                    Disabled
loopback                     Disabled
pagp-flap                    Disabled
port-mode-failure            Disabled
pppoe-ia-rate-limit          Disabled
psecure-violation            Enabled
security-violation           Disabled
sfp-config-mismatch          Disabled
small-frame                  Disabled
storm-control                Disabled
udld                         Disabled
vmps                         Disabled
psp                          Disabled

Timer interval: 30 seconds

Interfaces that will be enabled at the next timeout:

cisco 3850 端口镜像对性能的影响

下面是我做端口镜像的配置,注意:这里用了26个端口作为源,而目标只有一个端口。 想要关闭端口镜像,也很简单,下面no掉即可
monitor session 1 source interface g1/0/1 - 12 , g2/0/1 - 12 , g1/0/43,g2/0/43
 monitor session 1 destination int g2/0/48
 
 no monitor session 1
等我做完配置之后,查看这么大流量对CPU于内存的消耗,发现CPU的提高几乎没有,内存的增加几乎可以忽略。
所以端口镜像对设备性能的影响其实可以忽略不计。
所以大家尽量大胆尝试。


下面是我镜像后的在Ntopng流量





镜像一天就有300多G的流量了

2016年10月22日星期六

cisco 交换机 SNMP OID 查询 与 Zabbix 监控

第一种办法
SNMP Object Navigator
Cisco IOS MIB Locator

第二种办法
show snmp mib | in xxx
SNMP Object Navigator 


cisco的snmp会有一个问题,就是之前监控的oid,重启后就会变得不一样,
这样每次重启设备后,都需要再手动添加一些oid,这会很恼人。
这是一个官方的配置链接,配置snmp oid持久化的方法

要对cisco snmp oid 进行测试,首先要安装snmpwalk。
命令:
         yum install -y net-snmp net-snmp-utils

snmp v3的测试方法:
      snmpwalk -v 3 -u ITSEC -a sha -A gohciuY2tu -x AES -X il4laht9Pi -l authPriv 172.16.2.2
       

2016年10月19日星期三

ASA日志量太多的解决办法

ASA日志量太多的解决办法

asa的用途是在公司连接百兆的光纤上网,但是每天都会有大量的日志,
而且那些日志一点用处都没有,可以通过以下命令去禁止无用的日志输出到syslog服务器
asa如果没有过滤的话一个月会生成1000多w的日志,太大了

XYJ-ASA5512-B(config)# show logging message 106001
syslog 106001: default-level critical (enabled)
XYJ-ASA5512-B(config)# no logg
XYJ-ASA5512-B(config)# no logging me
XYJ-ASA5512-B(config)# no logging message 106001
XYJ-ASA5512-B(config)# no logging message 106006
XYJ-ASA5512-B(config)# no logging message 106014
XYJ-ASA5512-B(config)# no logging message 106023
XYJ-ASA5512-B(config)# no logging message 500004
XYJ-ASA5512-B(config)# no logging message 410001
XYJ-ASA5512-B(config)# no logging message 733100
XYJ-ASA5512-B(config)# no logging message 106007
Oct 19 2016 15:10:02: %ASA-5-111008: User 'enable_15' executed the 'no logging message 106001' command.
Oct 19 2016 16:38:56: %ASA-5-111008: User 'enable_15' executed the 'no logging message 733100' command. 
我是用logAnalyzer去收集日志的,以下是删除一些无用日志的sql语句。
delete from SystemEvents where Message like '%Inbound TCP%' and Syslogtag = '%ASA-2-106001:';
delete from SystemEvents where Message like '%Inbound TCP%' and Syslogtag = '%ASA-2-106001:';
delete from SystemEvents where Message like '%inbound UDP%' and Syslogtag = '%ASA-2-106006:';
delete from SystemEvents where Message like '%inbound icmp%' and Syslogtag = '%ASA-3-106014:';
delete from SystemEvents where Message like '%Deny udp src%' and Syslogtag = '%ASA-4-106023:';
delete from SystemEvents where Message like '%Deny icmp src%' and Syslogtag = '%ASA-4-106023:';
delete from SystemEvents where Message like '%Invalid transport field%' and Syslogtag = '%ASA-4-500004:';
delete from SystemEvents where Message like "%executed the 'enable'%" and Syslogtag = '%ASA-5-111008:';
delete from SystemEvents where Message like '%executed the \'enable\'%' and Syslogtag = '%ASA-5-111008:';
delete from SystemEvents where Message like '%Dropped UDP DNS%' and Syslogtag = '%ASA-4-410001:';
delete from SystemEvents where Message like '%User priv level changed%' and Syslogtag = '%ASA-5-502103:';
delete from SystemEvents where Message like '%User logged out: Uname: admin%' and Syslogtag = '%ASA-5-611103:';
delete from SystemEvents where Message like '%Received encrypted packet with no matching SA%' and Syslogtag = '%ASA-5-713904:';
delete from SystemEvents where Message like '%Current burst%' and Syslogtag = '%ASA-4-733100:';
delete from SystemEvents where Message like '%TCP access denied by ACL%' and Syslogtag = '%ASA-3-710003:';
delete from SystemEvents where Message like '%Duplicate TCP SYN from%' and Syslogtag = '%ASA-4-419002:';
delete from SystemEvents where Message like '%Deny inbound UDP from%' and Syslogtag = '%ASA-2-106007:';
delete from SystemEvents where Message like '%No matching connection for ICMP%' and Syslogtag = '%ASA-4-313005:';
delete from SystemEvents where Message like '%Group = spoke1%' and Syslogtag = '%ASA-5-713120:';
delete from SystemEvents where Message like '%Group = spoke1%' and Syslogtag = '%ASA-5-713119:';
delete from SystemEvents where Message like '%Group = spoke1%' and Syslogtag = '%ASA-5-713049:';
delete from SystemEvents where Message like '%Group = spoke1%' and Syslogtag = '%ASA-5-713041:';
delete from SystemEvents where Message like '%Denied ICMP type=3, code=3 from%' and Syslogtag = '%ASA-3-313001:';
delete from SystemEvents where Message like '%Dropped connection for ESMTP Request%' and Syslogtag = '%ASA-4-108004:';
delete from SystemEvents where Message like '%Received Invalid Cookie message for non-existent SA%' and Syslogtag = '%ASA-4-713903:'; 
delete from SystemEvents where Message like '%tcp flow from lan%' and Syslogtag = '%ASA-4-507003:';

2016年10月18日星期二

15.0 SE5 DHCP snooping bug

CISCO 2960  IOS 15.0(2) SE5
Switch Ports Model              SW Version            SW Image                 
------ ----- -----              ----------            ----------               
*    1 50    WS-C2960+48TC-L    15.0(2)SE5            C2960-LANBASEK9-M        

Configuration register is 0xF

配置 DHCP snooping后,show ip dhcp snooping 显示都正常

XYJ-C2960_11#show ip dhcp snooping 
Switch DHCP snooping is enabled
DHCP snooping is configured on following VLANs:
1-100
DHCP snooping is operational on following VLANs:
1-2,4-18,20-25,100
DHCP snooping is configured on the following L3 Interfaces:

Insertion of option 82 is enabled
   circuit-id default format: vlan-mod-port
   remote-id: 84b5.17ea.5c80 (MAC)
Option 82 on untrusted port is not allowed
Verification of hwaddr field is enabled
Verification of giaddr field is enabled
DHCP snooping trust/rate is configured on the following Interfaces:

Interface                  Trusted    Allow option    Rate limit (pps)
-----------------------    -------    ------------    ----------------   
GigabitEthernet0/1         yes        yes             unlimited
  Custom circuit-ids:
GigabitEthernet0/2         yes        yes             unlimited
  Custom circuit-ids:
Port-channel1              yes        yes             unlimited
  Custom circuit-ids:


但是untrust口依然放行 DHCP offer包,
并且在  show  ip dhcp snooping binding 没有显示任何有效条目

XYJ-C2960_11#show ip dhcp snooping binding 
MacAddress          IpAddress        Lease(sec)  Type           VLAN  Interface
------------------  ---------------  ----------  -------------  ----  --------------------
Total number of bindings: 0

XYJ-C2960_11#
XYJ-C2960_11#

最后去google一下,才知道这是该版本的一个BUG
url1  url2
只能通过升级上去解决问题。
 

给迈乐M6-天猫魔盒刷v1.2.1的系统

使用sd卡刷

我只有micro sd卡,但是加上一个SD卡套,就可以当SD卡使用了
v1.2.1 固件下载与说明地址 迈乐M6
我为什么要刷v1.2.1
因为我需要同时在hdmi与av输出音频信号,之前的天猫v1.6.x的系统不支持

 

备份系统

我为什么要备份系统?
因为我的micro sd卡是来自我的树莓派的,里面有安装系统了,所以要对系统进行备份
于是我在我的mac下备份:
  • 插入读卡器
  • 使用
    diskutil --list
    diskutil unmountdisk rdisk2
    
    卸载sd卡,注意:不要使用eject,否则无法dd成功
  • 使用dd命令去把磁盘数据导出为img文件
  • 下面是标准命令,bs是指一次复制多少内容,count是指复制多少次
    dd bs=10m count=500 if=/dev/rdisk2 of=./backup.img
  • 需要压缩的话可以这样:
    dd bs=10m count=500 if=/dev/rdisk2 | gzip -9 > ./backup.img.gz
  • 压缩文件的系统还原
    gzip -c -d backup.img.gz | dd bs=10m of=/dev/rdisk2
  • 查看dd执行进度
dd 是一个效率非常低的工具,但是却最可靠
在另外一个终端下执行下面的命令
watch -n 5 killall -USR1 dd

刷固件教程

1.把sd卡烧录好后
2.把魔盒断电
3.插入SD卡
4.魔盒加电
5.魔盒指示灯开始闪烁
6.指示灯不闪烁并且不亮就是刷机成功
7.拔下sd卡,并且断电
8.刷机成功,可以接上电视了

Mac os x 10.10.3 python2.7 与 python3 并存

测试别人的代码的时候难免会用到:pyhton3

我为什么会去安装python3?
因为我今天在python2.7下去import urllib.parse时,出现了错误,找不到模块
原因是python3才支持这样import

你可能需要brew

brew的安装方法

 

安装python3方法两种

1.使用brew安装
brew install python3
2.去官网下载指定版本的安装包

 

python3安装模块工具pip3

pip 默认只给python2.x安装模块
pip3 才可以给python3安装模块

sublime text 3 指定python3作为build system

Tools --> Build System --> New Build System
填入下面的配置
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python" }

然后保存文件名为python3.sublime-build,文件会自动保存到sublime的自定义文件夹中

mac下默认路径是
~/Library/Application Support/Sublime Text 3/Packages/User
然后你就可以根据需要在Build System下切换到不同的python解释器

pythonREPL 配置python交互模式

python RUN - Current File 配置文件路径
/Users/sherpper/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/python/Main.sublime-menu

"cmd": ["python", "-u","-i", "$file_basename"]
# 加入-i选项,运行完脚本后进入交互模式。-u 表示不缓冲

sublime text 3 输出中文提示"unicodeDecodeError"

测试环境中插入这段代码后就可以了,但是在实际使用中要把这段去掉
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())

 


新浪微博第三方登录的python实现

这是来自一个朋友的项目,需要在美拍用微博账号授权登录,我再本项目的技术力量薄弱

我可能在python算是入门了,但是web那块我还是空白的,我只知道http协议的基本工作过程 对于细节方面,要用到很多没少用的模块,比如 httplib, urllib, urllib2, htmllib等
  • 你可能需要Ipython
因为ipython是交互性的,测试代码非常方便,而且帮助功能也非常齐全。
ipython3 安装(适用于python3)
pip3 install ipython
pip3 install ipython[all]
ipython 安装(适用于python2.7)
pip install ipython
  • 究竟如何实现自动化,怎么实现最好?

 

1.模拟浏览器的模块

mechanize
pyv8
上面两个模块的简单介绍
Splinter : 简单介绍
selenium : demo使用详解

 

2.python调用其他py脚本返回值

我的需求是这样的,python2.7下面运行不了python3的代码
只能用调用的形式,而不能使用import的形式
使用os模块,调用系统命令执行
os.system('python3 /home/xxx.py') 只能返回0
os.popen('python3 /home/xxx.py') 这可以将脚本返回值进行导出

 

3.模拟http报文发送的模块

urllib2

urllib.urlencode() 是urllib2没有的方法,而这又是经常使用的功能

httplib

  • httplib 与 urllib 的区别
httplib比urllib更为底层,urllib很多实现都需要调用httplib
ps:
httplib2详细使用指南
httplib详细使用指南

 

urllib in python3

urllib跟urllib2变成一个package urllib,而不是模块
import urllib.request
import urllib.parse
Request = urllib.request.Request(url) 

 

解析html数据的两个模块 htmllib 与 beautifulsoup

htmllib的使用远比Beautifulsoup要麻烦很多,htmllib一定要修改基类才能够按照自定义的标签提取方法
而BeautifulSoup只要很简单的几行代码就可以实现,htmllib要写很多代码才可以实现,所以不推荐使用htmllib

BeautifulSoup 官方中文文档
BeautifulSoup 安装
BeautifulSoup 入门
BeautifulSoup 详解
BeautifulSoup 系列教材4篇

python3 BeautifulSoup 模块导入方法:
import bs4
from bs4 import BeautifulSoup
python2.7 BeautifulSoup 模块导入方法:
from bs4 import BeautifulSoup
 
HTMLParser 官方文档
HTMLParser 模块详解
HTMLParser 实际案例

configParse 与 json 模块

Python ConfigParser的使用
python3中用configparser对配置文件的读写
json编码与解码(官方文档)

 

2016年10月17日星期一

网络ping掉包原因

1. cpu使用率高
2. 网线问题,排除方法 show int g0/2,看crc校验值
3. 网口流量大,当流量占满接口带宽

cisco 日志时间戳

cisco 交换机 日志时间戳问题
默认,如果不配时间戳的话,就会使用0时区的时间,配一下这段后,才可以显示本地时间戳

  XYJ-C2960_9(config)#  
  XYJ-C2960_9#show clock  
  Oct 17 09:24:20: %SYS-5-CONFIG_I: Configured from console by admin on vty0 (172.16.11.198)  
  17:24:23.290 BeiJing Mon Oct 17 2016  
  XYJ-C2960_9#  
  XYJ-C2960_9(config)#  
  Oct 17 09:21:01: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to down  
  Oct 17 09:21:02: %LINK-3-UPDOWN: Interface FastEthernet0/23, changed state to down  
  Oct 17 09:21:05: %LINK-3-UPDOWN: Interface FastEthernet0/23, changed state to up  
  Oct 17 09:21:06: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to up  
  XYJ-C2960_9(config)#  
  XYJ-C2960_9(config)#service timestamps log datetime msec localtime show-timezone  
  XYJ-C2960_9(config)#service timestamps debug datetime msec localtime show-timezone  
  XYJ-C2960_9(config)#  
  Oct 17 17:25:40.481 BeiJing: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to down  
  Oct 17 17:25:42.494 BeiJing: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/23, changed state to up  

cisco 3850 上传镜像 与 FTP配置

引用下一篇文章:

Field Notice: Cisco IOS TFTP Client Cannot Transfer Files Larger than 16MB in Size

cisco IOS tftp客户端 不能够传输大于16MB的文件
我至少尝试使用 Tftpd32 and Tftpd64,cisco tftp server,还是linux下的tftp服务
都是会在传输中断开

最后我只能换其他办法,用FTP去完成任务
但是FTP也是不容易使用的

 XYJ-C2960_9#copy flash:c2960-lanbasek9-mz.150-2.SE8.bin ftp://ftp:@172.16.2.163   
 Address or name of remote host [172.16.2.163]?   
 Destination filename [c2960-lanbasek9-mz.150-2.SE8.bin]?   
 Writing c2960-lanbasek9-mz.150-2.SE8.bin   
 %Error opening ftp://*****@172.16.2.163/c2960-lanbasek9-mz.150-2.SE8.bin (Incorrect Login/Password)
 
 XYJ-C2960_9#copy flash:c2960-lanbasek9-mz.150-2.SE8.bin tftp:  
 Address or name of remote host []? 172.16.2.163  
 Destination filename [c2960-lanbasek9-mz.150-2.SE8.bin]?  
 !!.!.!.!!.!.!.....  
 %Error writing tftp://172.16.2.163/c2960-lanbasek9-mz.150-2.SE8.bin (Timed out)...  

其实我想实现的是,FTP服务器,允许匿名登录,并且有上传权限即可,

CentOS 6.3 下 vsftpd 匿名用户访问配置

可是没办法配置成功,最终采用了这种由用户登录的办法。

以下是FTP的配置办法,有用户列表的办法

 使用 yum 安装 vsftpd:  
             sudo yum install vsftpd  
 如果需要连接其他 FTP 服务器,则可以安装 FTP 客户端。  
             sudo yum install ftp 
 
 添加用户  
 adduser userftp  
 passwd userftp  
 禁止用户的 ssh 登录权限,只允许 FTP 访问:  
 usermod -s /sbin/nologin userftp 
 
 配置 VSFTP  
 打开配置文件:  
         sudo vi /etc/vsftpd/vsftpd.conf  
 关闭匿名访问:  
         anonymous_enable=NO  
 去掉 local_enable 的注释,修改为开启:  
         local_enable=YES  
 限制用户仅能访问自己的主目录:  
         chroot_local_user=YES  
 设置用户的主目录:(不设置时,默认为用户的家目录/home/userftp)  
         local_root=/data/test  
 重启服务:  
         sudo service vsftpd restart
 
 设置开机自启动:  
 chkconfig vsftpd on  
 连接测试  
 ftp userftp@112.126.74.124  
 ftp> pwd  
 Remote directory: /home/userftp  
 ftp> quit  
 221 Goodbye.  

最后show出我的成功案例
ftp://username:password@172.16.1.1
 XYJ-C2960_9#copy flash:c2960-lanbasek9-mz.150-2.SE8.bin ftp://imageup:!@#admin@172.16.1.1  
 Address or name of remote host [172.16.2.163]?   
 Destination filename [c2960-lanbasek9-mz.150-2.SE8.bin]?   
 Writing c2960-lanbasek9-mz.150-2.SE8.bin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
 11834846 bytes copied in 48.864 secs (242200 bytes/sec)  

2016年10月14日星期五

网络流量监测的用处

当有一天,有同事怀疑你的网络有问题的时候,
可以通过zabbix监控去看出是否出现过网络中断的情况,
这可以成为有力的证据

同样的防火墙的日志也是尤为重要的。

如果需要对网络进行访问控制策略的制定,但是你又不太了解网络的时候
这时候你需要科来的矩阵功能,加上ntopng的检索功能,它们可以帮你
完成不少的事情,最后不知道的再去询问吧。以下是使用方法:

 ntopng     +    科莱
     |
  检索 <------- 矩阵 
     |
  主机  -------------> Talker 查看实时流量
     |    \______________ 如果是web服务器,Flow查看url
     |
protocol
     |
服务器类型

2016年10月13日星期四

python 打印原始变量值

使用print打印出来,默认将 \r\n  or  \n 自动进行换行然后才输出的
要想输出不换行,并且打印出原始字符,就用 str()
看下面示例代码:

1:  @DELL-PC[C:startups]|1> a = 'sdafasdfhjkj\r\nsadfasdf'  
2:  @DELL-PC[C:startups]|2> a  
3:                      <2> 'sdafasdfhjkj\r\nsadfasdf'  
4:  @DELL-PC[C:startups]|3> print a  
5:  sdafasdfhjkj  
6:  sadfasdf  
7:  @DELL-PC[C:startups]|4> str(a)  
8:                      <4> 'sdafasdfhjkj\r\nsadfasdf'  
可以在测试正则表达式的地方派上用处

2016年10月12日星期三

python 模块之间调用变量与函数

python模块之间的变量调用与命名空间有很大关联

每个模块之间的变量都是独立的命名空间
而命名空间又有globals() 与locals()
所以使用global去定义全局变量是无法再模块之间去调用的 (已经通过实验证实)

当一行代码要使用变量 x 的值时,Python会到所有可用的名字空间去查找变量,按照如下顺序:
1.局部名字空间 - 特指当前函数或类的方法。如果函数定义了一个局部变量 x,Python将使用这个变量,然后停止搜索。
2.全局名字空间 - 特指当前的模块。如果模块定义了一个名为 x 的变量,函数或类,Python
  将使用这个变量然后停止搜索。
3.内置名字空间 - 对每个模块都是全局的。作为最后的尝试,Python将假设 x 是内置函数或变量。

所以只能通过以下方法实现:
1:  import sys  
2:      sys.module['__main__'].vars  

if __name__ = '__main__': 作用:
在模块测试代码的时候就用使用
如果在它之后的代码被运行,说明该模块是直接运行的,也就说主模块
如果在它之后的代码没有被运行,说明该模块是被模块调用的

比如有一个varmain.py脚本
varmain.py实际上是两个模块,一个是__main__,一个是varmain,也就是说,这个文件会被载入两次。
你设置的是__main__中的hello,不是varmain中的hello。

__init__.py文件的作用:
如果一个文件夹下面有这个文件,说明它被档次package使用了
当用该package的时候,这个文件就会被执行一遍

1:  附:模块查找的顺序  
2:        sys.path 可以查看到  
3:        sys.path.append 可以增加搜索路径  
4:        先是查找当前路径下  
5:        再去查找lib目录  
6:        最后是 site-packages  


Question:
还有python的原始关键字如何打印与保存,并且用于正则表达式的测试

参考链接:
1. python实现调用其他python脚本的方法,实现调用python脚本
2. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
3. Python 中的模块和包
4. Python导入模块的几种姿势
5. [Python学习] 专题六.局部变量、全局变量global、导入模块变量






2016年10月7日星期五

Ntopng 本地流量矩阵

部署环境
debian 8 jessie 
ntopng 3.0

1. 准备多一个网卡,用于接受镜像流量
2. 网卡配置混杂模式
#将下面两行加入/etc/rc.local
ifconfig eth1 up
ifconfig eth1 promisc

3. netstat -i 查看网口是否在 promiscuous 模式

      The flag will be updated to BMPRU. Flag details are as follows:
  • B flag is for broadcast
  • M flag is for multicast
  • P flag is for promisc mode
  • R is for running
  • U is for up
4. 在Debian环境下,是没有nbox这个软件包的,只在Ubuntu才有。

Ntopng配置

Local Hosts Active Flows Matrix功能

 提示

 No local hosts can be found   

 的解决方法

在配置文件中去定义哪些是本地网络,就可以再矩阵中看到,方便分析

ntopng 配置文件 /etc/ntopng/ntopng.conf  加入

 --local-networks="10.0.0.0/24,172.16.0.0/16,192.168.0.0/16"   

重新启动ntopng就可以看到流量矩阵了



参考链接: