正在加载……
Debian系统启动脚本
Posted in 情感天地 on April 16, 2007 / 评论(0) »
Debian GNU/Linux使用SysV模块作为系统初始脚本。与RH一样,Debian使用一个扩展的SysV模块,而Slackware主要是基于BSD的,并为了使用SysV模块而写了几个方便的脚本。
定位SysV目录
Debian GNU/Linux,与大多数使用SysV模块的系统一样,将相关的目录存放在/etc目录之下。也就是说,SysV目录/etc/init.d是脚本自身,而/etc/rc1.d,/etc/rc2.d直到/etc/rc6.d是特殊运行级别的目录。而管理所有这些的脚本为/etc/rc.d/rc。
然而RH7.2,是将SysV目录全部放在/etc/rc.d目录之下。也就是就说,RH使用/etc/rc.d/init.d,而不是/etc/init.d。为了兼容性,RH创建了一些由/etc指向/etc/rc.d下相关目录的链接。
使用Debian工具进行工作
RH包含了一些用于自动管理SysV初始脚本过程的工具,也就是chkconfig民service。Debian并包含这些工具,但是却提供相似的管理工具:update-rc.d与invoke-rc.d。
使用update-rc.d
Debian的update-rc.d与RH的chkconfig工具相类似。然而chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。这些工具有不同的命令行选项,但是却执行类似的功能。下表列出了update-rc.d的一些用法。如果要查看完整的信息,我们可以查阅相关的和册页。
命令                                        功能
update-rc.d -f <service> remove            从所有的运行级别配置目录中是删除指定的服务
update-rc.d <service> start <order> <runlevels>    配置服务在运行级别列表中按指定的顺序启动
update-rc.d <service> stop <order> <runlevels>    配置服务在运行级别列表中指定的顺序停止
update-rc.d与RH的chkconfig之间最大的不同就在于update-rc.d是要设置所以指向/etc/init.d目录下服务脚本的运行级别链接,而chkconfig是要每一个运行级别单独配置服务。从本质上来说,这也就意味着每次我们使用update-rc.d改变一个运行级别,我们就不得不改变所有的。例如,下面的命令序列与命令chkconfig -level 2345 inetd off的作用相同:
$ update-rc.d -f inetd remove
$ update-rc.d inetd stop 20 0 1 2 3 4 5 6 .
第一个命令移除了所有的指向/etc/init.d/inetd服务脚本的运行级别链接,-f标志将会使得update-rc.d即使在inetd脚本本身已经存在的情况仍然进行相应的处理。第二个命令在每一个运行级别创建了一个服务级别为20的停止脚本。例如,这会创建一个/etc/rc3.d/K20inetd的符号链接来禁止运行级别3中inetd的运行。(在这里我们要注意的是我们要显示的添加reboot与shutdown运行级别,即0和6,仅管其中所有的服务都会被设置成为“stop“)。作为另外的一个例子,下面所显示的命令将会在运行级别3到5允许inetd的运行,而在其他的运行级别中则被禁止:
$ update-rc.d -f inetd remove
$ update-rc.d inetd start 20 3 4 5 . stop 20 0 1 2 6 .
Debian的update-rc.d最初看起来会叫人有一些迷惑,但是旦我们明白,我们就会发现他可以多么出色的完成我们的工作。
使用invoke-rc.d
Debian下与RH的service命令作用等同的命令为invoke-rc.d。这两个命令在大多数情况下的作用是完全相同的。例如,service inetd start与invoke-rc.d inetd start有相同的作用(启动inetd服务,相应的停止服务的命令为invoke-rc.d inetd stop)。invoke-rc.d命令也有一个额外的我们可以深入研究的命令参数,但是一般来说这两个命令是相同的。
/etc/initta中的不同
主要配置系统初始化过程的文件是/etc/inittab。这个文件管理在系统启动时的脚本。下面的是与其他的发行版本中的inittab文件所不同的几个地方:
1 Debian的默认运行级别是2.
2 Debian并不会在/etc/inittab文件中中配置X Window系统显示管理器。
3 运行级别2与3是相同的,而运行级别4与5是相同的。
4 运行级别4与5只会运行一个虚拟终端,而运行级别2与3却会运行6个。
我的Ubuntu源
Posted in 情感天地 on April 14, 2007 / 评论(0) »
deb http://ubuntu.cn99.com/ubuntu/ feisty main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ feisty-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ feisty-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ feisty-proposed main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ feisty-backports main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ feisty main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ feisty-security main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ feisty-updates main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ feisty-proposed main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ feisty-backports main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu-cn/ feisty main restricted universe multiverse

deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty main restricted universe multiverse
deb-src http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty main restricted universe multiverse
deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-updates main restricted universe multiverse
deb-src http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-updates main restricted universe multiverse
deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-backports main restricted universe multiverse
deb-src http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-backports main restricted universe multiverse
deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-security main restricted universe multiverse
deb-src http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-security main restricted universe multiverse
deb http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-proposed main multiverse restricted universe
deb-src http://ubuntu.csie.ntu.edu.tw/ubuntu/ feisty-proposed main restricted universe multiverse

deb http://mirror.lupaworld.com/ubuntu feisty main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu feisty-security main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu feisty-updates main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu feisty-backports main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu feisty main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu feisty-security main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu feisty-updates main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu feisty-backports main restricted universe multiverse

deb http://ubuntu.beryl-project.org feisty main
如何用Opera在动网发贴
Posted in 情感天地 on April 10, 2007 / 评论(0) »
Opera对动网和其它如BBSXP论坛的支持一直有问题,这也是它一个致命伤,
常用的办法是添加View In IE标签,但显然这很麻烦
Opera官方论坛上somh编写了这样一个修复动网的脚本,可以解决回帖和PM的问题。

下载见附件,使用方法:
1.首先推荐大家了解这个问题,了解了这个会使你对Opera的操作更加得心应手(以下转自亡灵法师的BLOG)
配置文件和安装文件不在同一个目录的问题
Opera考虑了多用户使用Opera而需要不同配置的问题,默认安装的时候会将配置文件放到C:\Documents and Settings\你的用户名\Application Data\Opera\Opera\下面——即profile目录(负责用户设置等)和mail目录(负责电子邮件和新闻订阅)。

解决的方法:

一、卸载后重新安装的解决方法:
(1)、Opera 9.0正式版的国际多语言安装版本



(2)、Classic经典安装版本

经过上面的安装,profile目录和mail目录都会被放到X:\Program Files\Opera\下面,方便修改。
二、不需要重新安装的解决方法:
1、打开Opera安装目录下面的OperaDef6.ini,设置[System]下面的Multi User=0。
2、找到opera6.ini这个文件,它通常位于C:\Documents and Settings\你的用户名\Application Data\Opera\Opera\profile\下面,把其中的C:\Documents and Settings\你的用户名\Application Data\Opera\Opera\全部替换为X:\Program Files\Opera\(注:(X为你安装Opera的分区盘符,默认为C)。
3、把C:\Documents and Settings\你的用户名\Application Data\Opera\Opera\下面的profile目录和mail目录剪切到X:\Program Files\Opera\。


通过以上方法,你可以将Opera变成了绿色版本,如果软件不是装在系统盘,这样重装系统也不会对Opera有影响,你不用在重装系统后重做后边的操作,或者是重新配置,且配置文件和安装文件在同一目录下,方便操作

2.如果你不想要第一步操作,也对"如果用Opera在动网发帖"这个问题没有影响,继续第二步
在Opera的安装目录下,推荐在Profile目录下新建一文件夹"scrīpt",这个名字自定,最好英文
把附件下载的文件解压后放进去

3.接下来进入进入首选项——内容——Javascrīpt选项
将最下边的路径设置为刚才新建那个scrīpt目录的路径,如附图我的设置,点确定,重启浏览器
4.打开动网的的论坛,见到如下图那个红色的"Opera Browser"标签
恭喜你,你可以正常在动网或BBSXP论坛上发贴了




JS文件下载地址:
http://www.ctun.net/1/viewspace_2138
本文出自:http://www.nsfocus.com 维护:小四 (2002-10-30 06:02:01)
10.   网卡相关问题 
10.1  如何在程序中获取本机MAC地址 
10.2  如何在Sun工作站上安装3块网卡 
10.3  如何在Solaris x86上安装网卡驱动 
10.4  Solaris 单网卡多IP(以太网卡别名) 
10.5  如何修改主机名(hostname) 
10.6  SPARC/Solaris 2.5/2.6/7/8下如何设置网卡100Mb全双工 
10.7  Unix/Linux/BSD如何对抗ARP欺骗攻击 
10.8   
10.9   
10.10 
10.11 x86/Solaris如何强制设定网卡速率 
10.12 Solaris/FreeBSD/Linux如何确定网卡Capability/Speed 
10.13 
10.14 traceroute是怎么实现的 
-------------------------------------------------------------------------- 

10. 网卡相关问题 

10.1 如何在程序中获取本机MAC地址 

Q: 如何在C代码中获取本机MAC地址,我用strace跟踪ifconfig 

   ioctl(4, SIOCGIFHWADDR, 0xbffffb80)     = 0 
   ioctl(4, SIOCGIFADDR, 0xbffffb80)       = 0 
   ioctl(4, SIOCGIFBRDADDR, 0xbffffb80)    = 0 
   ioctl(4, SIOCGIFNETMASK, 0xbffffb80)    = 0 

D: Unix Programmer 

用gethostname()/gethostbyname()依赖于本机的域名解析系统,比如/etc/hosts文 
件、/etc/nsswitch.conf文件、/etc/resolv.conf文件。这样获取本机IP是不可靠的。 
如果/etc/hosts文件中没有指定本机IP,则依赖DNS是否配置了PTR资源记录。可靠的 
办法应该是strace ifconfig、truss ifconfig,实际就是照ifconfig的实现去获取 
本机IP。 

A: David Peter <dave.peter@eu.citrix.com> 

strace是Linux下的工具,由于HP-UX 10.20的ioctl不支持SIOCGIFHWADDR,可能需要 
DLPI接口或者针对/dev/lan0的NETSTAT ioctl,为了使用NETSTAT ioctl还需要重启 
动,而且HP不赞成继续使用NETSTAT ioctl,HP-UX 11.00不再支持。 

根据手头一个古老的工具,Digital Unix下ioctl支持SIOCRPHYSADDR。至于SGI上的 
IRIX,我想可能需要一个原始套接字,比如: 

s = socket( PF_RAW, SOCK_RAW, RAWPROTO_SNOOP ) 

D: scz <scz@nsfocus.com> 2001-11-20 11:46 

SPARC/Solaris下只有root用户才可以ifconfig -a看到本机MAC地址,普通用户并不 
能这样做,但可以尝试在dmesg输出中查找,由于dmesg使用的数据有可能被破坏,这 
个办法并不可靠。 

"arp <本机IP地址>"可以看到本机MAC地址,使用的技术实际上就是前面编程演示的 

ioctl( s, SIOCGARP, &arpreq ) 

此外还可以用如下命令获取本机MAC地址 

ndd /dev/arp arp_cache_report | grep MYADDR 

10.2 如何在Sun工作站上安装3块网卡 

Q: 我想在Sun工作站上安装3块网卡,怎么办 

A: Santosh 

请遵循如下步骤 

1) 在Sun工作站上增加网卡 

2) 用boot -r启动系统 

3) 观察启动信息,确认每块网卡都被识别出来,比如这种信息 

   PCI-device: network@1,1, hme #0 
   SUNW,hme0 is /pci@1f,4000/network@1,1 

   实际中如果每块网卡都被识别出来,有hme0、hme1 和 hme2,当然1和2可能不是 
   这个名字。 

4) 到/etc目录下创建hostname.hme0、hostname.hme1 和 hostname.hme2。在每个文 
   件中分别指定IP地址,编辑/etc/hosts文件增加相应入口。 

5) 重启机器 

10.3 如何在Solaris x86上安装网卡驱动 

A: James Adkins <jadkins@peregrine.com> 

不需要修改"pcn.conf"文件。开始我只是"touch /reconfigure",Solaris x86检测 
到了网卡,但是"ifconfig -a"的时候只有loopback接口,于是我尝试如下步骤: 

# drvconfig 
# devlinks 
# touch /reconfigure 

重启动后一切ok 

10.4 Solaris 单网卡多IP(以太网卡别名) 

Q: 对于Solaris 2.5.1来说,可以在一块物理网卡上配置多个IP地址 

A: Sun Microsystems 1998-03-31 

下面以lance ethernet (le0) 设备为例说明 

1) 编辑/etc/hosts文件 

128.195.10.31 myhost 
128.195.10.46 myhost2 
128.195.10.78 myhost3 

2) 创建/etc/hostname.le0:n文件,注意hostname.le0:0就是hostname.le0 

/etc/hostname.le0   (Contains name myhost) 
/etc/hostname.le0:1 (Contains name myhost2) 
/etc/hostname.le0:2 (Contains name myhost3) 

注意这种文件就一行内容,主机名。 

3) 如果想立即生效 

% ifconfig le0:1 up 
% ifconfig le0:1 129.153.76.72 
% ifconfig le0:1 down 

Q: Solaris 8下如何给一块以太网卡赋予多个IP地址? 

A: Vadim V. Kouevda <VKouevda@pcinetgw.is.bear.com> 

ifconfig le0 plumb 
ifconfig le0 ether 0:1:2:3:4:5 
ifconfig le0:1 plumb 
ifconfig le0:1 ... up 
ifconfig le0:2 plumb 
ifconfig le0:2 ... up 

到/etc/init.d目录下修改IP地址、子网掩码等设置。 

D: scz <scz@nsfocus.com> 

有三个文件需要注意,/etc/rcS.d/S30rootusr.sh(/etc/init.d/rootusr)、 
/etc/rc2.d/S69inet(/etc/init.d/inetinit)和/etc/rc2.d/S72inetsvc 
(/etc/init.d/inetsvc)。 

Q: 如何在一块物理网卡上绑定多个IP地址 

A: Sun Microsystems 1997-10-27 

所谓虚拟网络接口指一个物理接口多个不同IP地址,Solaris允许一个物理网络接口 
对应多个逻辑接口,换句话说,即使只有一块网卡,也可以配置多个IP地址。参看 
ifconfig(1M)手册页。对于Solaris 2.x,可以在一块网卡上绑定256个不同IP地址。 
Sun OS 4.x(Solaris 1.x)不支持。 

/usr/sbin/ndd -get /dev/ip ip_addrs_per_if 

对于Solaris 2.6,通过ndd可以配置超过256(0-255)个IP地址。 

/usr/sbin/ndd -set /dev/ip ip_addrs_per_if 1-8192 

将这条命令增加到/etc/rc2.d/S69inet启动脚本中去。 

1) 编辑/etc/hosts文件(或者nis host map),为每个虚拟接口增加条目。别忘记修 
   改NIS、NIS+、DNS数据库。 

2) 为每个接口创建/etc/hostname.<interface:#>文件,比如/etc/hostname.le0:1、 
   hostname.le0:2、hostname.le0:3 ... le0:255。文件内容为单行IP地址或者主 
   机名。比如创建如下文件 

   /etc/hostname.le0:1  (不要使用le0:0,那就是le0) 
   /etc/hostname.le0:2 

   Solaris 2.5.1下最多1024个虚拟接口。每个文件内容是自己对应的虚拟接口IP地 
   址或者主机名。 

3) 如果使用了子网,应该在/etc/netmasks中增加 

   network_address  netmask 

   157.145.0.0  255.255.255.0 

4) 重启系统 

5) ifconfig -a验证之 

某些第三方应用程序此时可能会出问题。出于安全考虑,可以 

ndd -set /dev/ip ip_forwarding 0 
ndd -set /dev/ip ip_strict_dst_multihoming 1 

参看RFC1112 - <<Host Extensions for IP Multicasting>>。 

如果因为配置虚拟接口出现不期望的路由,考虑手动"route delete"。可以增加一个 
启动脚本/etc/rc2.d/S99vif,用于完成这些任务。 

对于Solaris 2.6,可能还需要 

ndd -set /dev/ip ip_enable_group_ifs 0 (2.6下缺省是1,7下缺省是0) 

将这条命令增加到/etc/rc2.d/S69inet启动脚本中去。 

10.5 如何修改主机名(hostname) 

Q: Solaris 2.6下如何修改主机名(hostname) 

A: Herve Poussin <poussin@partner-system.com> 

需要修改如下文件 

/etc/hosts 
/etc/hostname.<interface> 
/etc/nodename 
/etc/net/*/hosts (3 files, man -s 7D ticotsord) 

如果你运行在VxVM下,则应该 

# vxdctl hostid <new_name> 
# vxdctl init <new_name> 

10.6 SPARC/Solaris 2.5/2.6/7/8下如何设置网卡100Mb全双工 

Q: 我从SPARC连接3Com交换机时,总是使用半双工,如何配置网卡强行使用100Mb全 
   双工 

A: Martin Scerri <martin_scerri@bigfoot.com> 

下列回答来自"Sun管理员FAQ 12.3",并且只适合于Solaris 2.5及其以后版本, 
Sun OS 4.x及其更早版本不支持hme接口。 

一般网卡可以和交换机自动协商使用100Mb全双工,如果协商失败,可能看到诸如 
"late collision"一类的消息,出现丢包甚至完全不能工作的现象。为了强行指定使 
用某一确定的工作模式,比如100Mb FD,可以用ndd做如下操作: 

# 指定操作hme0接口 
ndd -set /dev/hme instance 0 
# 关闭自动协商 
ndd -set /dev/hme adv_autoneg_cap  0 
# 打开100Mb FD支持 
ndd -set /dev/hme adv_100fdx_cap   1 
# 关闭100Mb HD支持 
ndd -set /dev/hme adv_100hdx_cap   0 
# 关闭10Mb FD支持 
ndd -set /dev/hme adv_10fdx_cap    0 
# 关闭10Mb HD支持 
ndd -set /dev/hme adv_10hdx_cap    0 

同样需要在对端(比如交换机)强行指定使用100Mb FD模式。 

注意:Fast ethernet hubs 总是使用100Mb HD模式 
      ethernet hubs 总是使用10Mb HD模式 

如果你想强行指定系统中所有hme网卡在启动时进入同一确定模式,可以在 
/etc/system文件中设置,下例表示进入100Mbit FD模式: 

set hme:hme_adv_autoneg_cap=0 
set hme:hme_adv_100fdx_cap=1 
set hme:hme_adv_100hdx_cap=0 
set hme:hme_adv_10hdx_cap=0 
set hme:hme_adv_10fdx_cap=0 

A: Andreas.Gouder <Andreas.Gouder@t-online.de> 

你可以用如下命令获取当前设置 

# ndd -get /dev/hme link_mode 

0 半双工 
1 全双工 

# ndd -get /dev/hme link_status 

0 Link Down 
1 Link up 

# ndd -get /dev/hme link_speed 

0 10Mbps 
1 100Mbps 

10.7 Unix/Linux/BSD如何对抗ARP欺骗攻击 

Q: Solaris的静态ARP表项(arp -s)还是会被动态刷新,我只确认Linux/FreeBSD的静 
   态ARP表项不会被动态刷新,到底有没有稍微通用点的对抗ARP欺骗攻击的方法。 

A: scz <scz@nsfocus.com> 

下面以Solaris系统为例说明,其他系统大同小异。 

1) 建立静态ARP表 

/usr/bin/touch /etc/static_arp_entry 
/usr/bin/chown root:root /etc/static_arp_entry 
/usr/bin/chmod 600 /etc/static_arp_entry 

编辑/etc/static_arp_entry文件,输入类似内容 

192.168.8.90    00:00:00:11:11:11 

/usr/sbin/arp -s -f /etc/static_arp_entry 

可以在/etc/rc2.d/S69inet启动脚本中增加这条命令。参看arp(1M)、arp(7P)手册页 
了解更多细节。这种技术对系统影响不大,对网络影响较大,破坏了动态ARP解析过 
程。Solaris系统中,静态ARP表不会过期,必须用"arp -d"手动删除。但是, 
Solaris系统的静态ARP表项可以被动态刷新,仅仅依靠静态ARP表项并不能对抗ARP欺 
骗攻击,相反纵容了ARP欺骗攻击,因为虚假的静态ARP表项不会自动超时消失。当然, 
可以考虑利用cron机制补救之。(增加一个crontab) 

为了对抗ARP欺骗攻击,对于Solaris系统来说,应该结合"禁止相应网络接口做ARP解 
析"和"使用静态ARP表"的设置 

2) 禁止某个网络接口做ARP解析(对抗ARP欺骗攻击) 

"/sbin/ifconfig hme0 -arp"命令将禁止hme0接口做ARP解析,hme0接口不会发送/接 
收ARP报文。必须配合使用静态ARP表,否则无法完成正常网络通信。参看 
ifconfig(1M)了解更多细节。假设/etc/rc2.d/S69inet启动脚本中存在如下内容 

/sbin/ifconfig hme0 -arp 
/usr/sbin/arp -s -f /etc/static_arp_entry 

假设/etc/static_arp_entry文件内容如下 

192.168.8.90    00:00:00:11:11:11 

这里192.168.8.90是一台PWin98,也做静态ARP设置(因为对方不会响应ARP请求报文) 

arp -s 192.168.10.6 08-00-20-a8-2e-ac 

此时192.168.8.90与192.168.10.6可以正常通信,并且192.168.10.6不受ARP欺骗攻 
击的影响。事实上,绝大多数Unix/Linux/BSD操作系统,都可以结合"禁止相应网络 
接口做ARP解析"和"使用静态ARP表"的设置来对抗ARP欺骗攻击。对于Linux/FreeBSD 
系统,因为其静态ARP表项(arp -s)不会被动态刷新,所以不需要"禁止相应网络接口 
做ARP解析"即可对抗ARP欺骗攻击。 

10.11 x86/Solaris如何强制设定网卡速率 

Q: x86/Solaris,我如何强行指定网卡的工作状态为100Mbps full-duplex,ndd(1M) 
   不工作 

A: CERNET 水木清华 Unix版 inc 2001-10-11 20:29 

x86/Solaris下的网卡驱动不支持ndd(1M)设置网卡工作状态,要达到目的,唯一的办 
法是通过driver.conf(4)指定。x86/Solaris 8的iprb(7D)手册页建议使用 
ForceSpeedDuplex选项。对于其它驱动,参看如下例子 

vi /kernel/drv/iprb.conf  <-- 用ifconfig -a确认一下 

# To force full duplex operation, uncomment the following line: 
# full-duplex=1; 

# To force half duplex operation, uncomment the following line: 
# full-duplex=0; 

# To force 10Mbps operation, uncomment the following line: 
# speed=10; 

# To force 100Mbps operation, uncomment the following line: 
# speed=100; 

奇怪的是iprb.conf原来没有上面的内容,elxl.conf却有。注意,不同网卡是有区别 
的,我试了RealTek RTL8139/8129、3Com 3C905B TX、Intel,只有Intel的可以这样 
修改,RealTek RTL8029的我不确定。 

D: CERNET 水木清华 Unix版 2001-10-12 10:36 

由于x86下网卡驱动不支持ndd(1M)获取网卡状态,被迫使用netstat -k 

ifconfig -a 找出网络接口名 

netstat -k <interface> | grep ifspeed 

某些x86网卡驱动支持,某些不支持,这个办法同样适合于SPARC网卡驱动,虽然后者 
可以直接使用ndd(1M)。 

10.12 Solaris/FreeBSD/Linux如何确定网卡Capability/Speed 

A: 小四 <scz@nsfocus.com> 2001-12-07 17:06 

Solaris 

# netstat -k hme0 | grep ifspeed 

# ndd -get /dev/hme link_mode 

0 半双工 
1 全双工 

# ndd -get /dev/hme link_status 

0 Link Down 
1 Link up 

# ndd -get /dev/hme link_speed 

0 10Mbps 
1 100Mbps 

FreeBSD用ifconfig就可以看到 

status: active      <-- 网线接到一个HUB上了 
status: no carrier  <-- 未接网线 

Linux和Windows系列我到现在也不确认。 

A: starw@smth.org 

在高版本的Linux系统中net-tools包中有一个mii-tool命令,可以用于检查这些数据, 
而不是溶合在ifconfig的输出中。 

10.14 traceroute是怎么实现的 

Q: traceroute是怎么实现的 

A: 小四 <cloudsky@263.net> 

traceroute(对于Windows系列是tracert)通过逐步增加TTL值的方法,发送常规IP分 
组来实现。第一次发送分组时TTL为1,第一个路由器接收到该分组之后将TTL值减1, 
结果为0,于是就丢弃该分组,并发回一个"TTL超时"的ICMP报文,该报文的源地址是 
这第一个路由器。紧接着发送一个TTL为2的分组。注意,traceroute发送常规的UDP 
报文到一个不用的UDP端口。当初考虑将路由跟踪的功能加入IP协议本身,定义一个 
"路由跟踪"选项,路由器处理带有该选项的IP包时立即发回一个跟踪报文到源站点。 
然而这种做法还停留在实验室阶段,因为这需要改变所有已经存在的路由器,而且在 
某种程度上与端到端原则相违背。 

1) 传统的Unix实现是UDP+ICMP 
2) 其实从原理上TCP+ICMP也是可以的,某些Unix系统采用了这种实现 
3) Windows另有一种实现,Icmp Echo Request+ICMP 
  1. #include <iostream>   
  2. #include <string>   
  3. #include <fstream>   
  4. #include <list>   
  5. #include <algorithm>   
  6. #include <vector>   
  7. #include <set>   
  8. using namespace std;   
  9. typedef list<string> ListStr;   
  10. typedef set<string> SetStr;   
  11. typedef ListStr::iterator Iter;   
  12. typedef SetStr::iterator s_iter;   
  13. typedef basic_string<char>::size_type S_T;   
  14. static S_T npos = -1;   
  15. string CONFIG_FILE;   
  16. string LOG_FILE;   
  17. const string DEFAULT_CONFIG_FILE="/root/config.txt";   
  18. const string DEFAULT_LOG_FILE="/root/log.log";   
  19. ////////////////////////////////////////////////////////   
  20. //Func Define   
  21. ////////////////////////////////////////////////////////   
  22. void splitstr(const string& _source,const string& _split,ListStr& _ls);   
  23.   
  24. vector<string> split(const string& src, string delimit, string null_subst);   
  25.   
  26. bool IsInMACAndIP(const ListStr& _ls,const string& _s);   
  27.   
  28. int ParseArg(int argc,char *argv[]);   
  29.   
  30. string getip(const string& _s);   
  31.   
  32. string getmac(const string& _s);   
  33.   
  34. int main(int argc,char *argv[]){   
  35. /////////////////////////////////////////////////////////////   
  36. //Define Data   
  37. /////////////////////////////////////////////////////////////   
  38.   ListStr IPAndMac;   
  39.   ListStr LogStr;   
  40.   ListStr ExecLogStrCount;   
  41.   SetStr ExecLogStr;   
  42.   Iter i_im;   
  43.   Iter i_ls;   
  44.   s_iter s_i;   
  45. //////////////////////////////////////////////////////////////   
  46. //Initial Data   
  47. //////////////////////////////////////////////////////////////   
  48. //    
  49.   int i_r = ParseArg(argc,argv);   
  50.   if(i_r <= 0){   
  51.     cout << "Error Params" << endl;   
  52.     exit(0);   
  53.   }else{   
  54.      
  55.     fstream fs_config(CONFIG_FILE.c_str());   
  56.     //cout << CONFIG_FILE << endl;   
  57.     fstream fs_log(LOG_FILE.c_str());   
  58.     //cout << LOG_FILE << endl;   
  59.     IPAndMac.clear();   
  60.     LogStr.clear();   
  61.     ExecLogStr.clear();   
  62.     ExecLogStr.clear();   
  63. ///////////////////////////////////////////////////////////////   
  64. //Exception   
  65. ///////////////////////////////////////////////////////////////   
  66.     if(!fs_config ){   
  67.       cout <<"Can not Open Config File " <<CONFIG_FILE <<  endl;   
  68.       exit(0);   
  69.     }   
  70.     if(!fs_log){   
  71.       cout <<" Can not Open Log File " << LOG_FILE << endl;   
  72.       exit(0);   
  73.     }   
  74.     else{   
  75. ////////////////////////////////////////////////////////////   
  76. //Read Config   
  77. ///////////////////////////////////////////////////////////   
  78.       string s_config_line;   
  79.       while(getline(fs_config,s_config_line)){   
  80.         IPAndMac.push_back(s_config_line);   
  81.       }   
  82. //////////////////////////////////////////////////////////   
  83. //Read Log   
  84. ////////////////////////////////////////////////////////////   
  85.       string s_log_line;   
  86.       while(getline(fs_log,s_log_line)){   
  87.         LogStr.push_back(s_log_line);   
  88.       }   
  89. //////////////////////////////////////////////////////////   
  90. //Do Test Data   
  91. /////////////////////////////////////////////////////////   
  92.     // NOw Get All Default Mac And Data   
  93.     //For LogStr   
  94.       //Get ARP IP And Mac   
  95.       //Is In IP And Mac   
  96.         //if In   
  97.         //else not  >>>>>> Arp Attack Cout IP And Address   
  98.       for(i_ls = LogStr.begin(); i_ls != LogStr.end() ; ++ i_ls){   
  99.         vector<string> v = split(*i_ls," ","");   
  100.         string s_IP = v[9];   
  101.         string s_MAC = v[1];   
  102.         string s_temp = s_MAC + "=" + s_IP;   
  103.         ExecLogStr.insert(s_temp);   
  104.         ExecLogStrCount.push_back(s_temp);   
  105.       }   
  106.   
  107.       for(s_i = ExecLogStr.begin(); s_i != ExecLogStr.end(); ++ s_i){   
  108.         if(!IsInMACAndIP(IPAndMac,*s_i)){   
  109.           int i_num = count(ExecLogStrCount.begin(),ExecLogStrCount.end(),*s_i);   
  110.           cout << "The Computer@@@" << *s_i <<"@@@Attack@@@" <<i_num <<"@@@Times!"<< endl;   
  111.         }   
  112.   
  113.       }   
  114.   
  115.     }   
  116.     return 0;   
  117.   }   
  118. }   
  119. string getip(const string& _s){   
  120.   return "";   
  121. }   
  122.   
  123. string getmac(const string& _s){   
  124.   return "";   
  125. }   
  126. void splitstr(const string& _source,const string& _split,ListStr& _ls){   
  127.   //todo:   
  128.   _ls.clear();   
  129.   string strtemp;   
  130.   strtemp = _source;   
  131.   string::size_type len = _source.length();   
  132.   string::size_type itmp = strtemp.find(_split);   
  133.   do{   
  134.     _ls.push_back(strtemp.substr(0,itmp));   
  135.     //cout << strtemp.substr(0,itmp) << endl;   
  136.        
  137.     if(len-itmp-1 > 0){   
  138.       //cout << strtemp << endl;   
  139.       strtemp = strtemp.substr(itmp+1,len-itmp-1);   
  140.       //cout << strtemp << endl;   
  141.       itmp = strtemp.find(_split);   
  142.       len = strtemp.length();   
  143.     }   
  144.     else{   
  145.       cout << 2 << endl;   
  146.       break;   
  147.     }   
  148.   }while( itmp>0 );   
  149.   //ListStr.push_back(_source.substr(0,i1));   
  150.   //cout << _source.substr(0,i1) << endl;   
  151.   //cout << _source.substr(i1+1,len-i1-2)<< endl;   
  152.   //cout << il << endl;   
  153. }   
  154. bool IsInMACAndIP(const ListStr& _ls,const string& _s){   
  155.   ListStr::const_iterator i = find(_ls.begin(),_ls.end(),_s);   
  156.   if(i == _ls.end()){   
  157.     return false;   
  158.   }   
  159.   else{   
  160.     return true;   
  161.   }   
  162. }   
  163. vector<string> split(const string& src, string delimit, string null_subst="")   
  164. {   
  165.   if( src.empty() || delimit.empty() ) throw "split: empty string\0";   
  166.   
  167.   vector<string> v;   
  168.   S_T deli_len = delimit.size();   
  169.   long index = npos, last_search_position = 0;   
  170.   while( (index=src.find(delimit, last_search_position))!=npos )   
  171.   {   
  172.     if(index==last_search_position)   
  173.       v.push_back(null_subst);   
  174.     else  
  175.       v.push_back( src.substr(last_search_position, index-last_search_position) );   
  176.     last_search_position = index + deli_len;   
  177.   }   
  178.   string last_one = src.substr(last_search_position);   
  179.   v.push_back( last_one.empty()? null_subst:last_one );   
  180.   return v;   
  181. }    
  182.   
  183. int ParseArg(int argc,char *argv[]){   
  184.   /*  
  185.   for(int i = 0 ; i < argc ; i++)  
  186.   {  
  187.     //cout << argc << endl;  
  188.     cout << argv[i] << endl;  
  189.   }  
  190.   */  
  191.   if(argc == 1){   
  192.     CONFIG_FILE = DEFAULT_CONFIG_FILE;   
  193.     LOG_FILE = DEFAULT_LOG_FILE;   
  194.     return argc;   
  195.   }   
  196.   else if(argc == 3){   
  197.     //cout << 3333 << endl;   
  198.     char tbuf[256];   
  199.     strcpy(tbuf,argv[1]);   
  200.     string s_temp = (string)(tbuf);   
  201.     if(s_temp == "-c"){   
  202.       //cout << 1111 << endl;   
  203.       char buf[256];   
  204.       strcpy(buf,argv[2]);   
  205.       CONFIG_FILE = (string)(buf);   
  206.       LOG_FILE = DEFAULT_LOG_FILE;   
  207.       //cout << CONFIG_FILE << endl;   
  208.       return argc;   
  209.     }   
  210.     if(argv[1] == "-l"){   
  211.       char buf[256];   
  212.       strcpy(buf,argv[2]);   
  213.       LOG_FILE = (string)(buf);   
  214.       CONFIG_FILE = DEFAULT_CONFIG_FILE;   
  215.       //cout << LOG_FILE << endl;   
  216.       return argc;   
  217.     }   
  218.   }   
  219.   else if(argc == 5){   
  220.     char tbuf1[256];   
  221.     strcpy(tbuf1,argv[1]);   
  222.     string s_temp1 = (string)(tbuf1);   
  223.   
  224.     char tbuf2[256];   
  225.     strcpy(tbuf2,argv[3]);   
  226.     string s_temp2 = (string)(tbuf2);   
  227.     if(s_temp1 == "-c" || s_temp1 == "-C")   
  228.       CONFIG_FILE = (string)argv[2];   
  229.     if(s_temp2 == "-l" || s_temp2 == "-L")   
  230.       LOG_FILE = (string)argv[4];   
  231.     //cout << CONFIG_FILE << "@@@@@" << LOG_FILE << endl;   
  232.     return argc;   
  233.   }   
  234.   else{   
  235.     return -1;   
  236.   }   
  237. }   

from:

http://www.libing.net.cn/read.php?911

分页: 112/170 第一页 上页 107 108 109 110 111 112 113 114 115 116 下页 最后页 [ 显示模式: 摘要 | 列表 ]