
2011年1月5日
转自:http://www.lanzs.cn/blog/archives/113/
服務名稱 |
建議 |
說明 |
| acpid |
停用 |
Advanced Configuration and Power Interface 電源進階設定,常用在 Laptop 上 |
| apmd |
停用 |
Adventage Power Management daemon 偵測系統的電池電量,常用在 Laptop 上 |
| atd |
停用 |
/etc/at.allow,/etc/at.deny 我大概都使用 crond 來達成 |
| autofs |
停用 |
自動掛載檔案系統與週邊裝置 (如光碟、USB),常用在 Laptop 上 |
| avahi-daemon |
停用 |
當區網沒有 DNS 服務時會試著尋找提供 zeroconf 協定的主機 |
| bluetooth |
停用 |
Bluetooth 藍芽,常用在 Laptop 上 |
| cpuspeed |
停用 |
控制 CPU 速度主要用來省電,常用在 Laptop 上 |
| cups |
停用 |
Common UNIX Printing System 使系統支援印表機 |
| firstboot |
停用 |
安裝完成後第一次啟動時的服務,設定 auth、firewall、keyboard… |
| gpm |
停用 |
記錄週邊裝置的檔案資料,例如文字模式下可使用滑鼠 |
| haldaemon |
停用 |
使系統支援 plug and play 裝置 |
| hidd |
停用 |
使系統支援藍芽裝置,例如滑鼠,鍵盤 |
| hplip |
停用 |
使系統支援 HP 相關型號印表機 |
| ip6tables |
停用 |
使系統支援 IPTables Filrewall IPv6 |
| isdn |
停用 |
使系統支援 Integrated Services Digital Network (ISDN) 環境 |
| lm_sensors |
停用 |
使系統支援偵測主機版或硬體,常用在 Laptop 上 |
| messagebus |
停用 |
使系統支援 plug and play 裝置 |
| nfslock |
停用 |
使系統支援 NFS Server 資料一致性功能 |
| pcscd |
停用 |
使系統支援 Smart Card |
| portmap |
停用 |
使系統支援 NFS Service |
| rpcgssd |
停用 |
使系統支援 NFSv4 Service |
| rpcidmapd |
停用 |
使系統支援 NFSv4 Service |
| yum-updatesd |
停用 |
使系統支援 YUM 自動更新服務 (上線機器還是先確認好再更新) |
| |
| anacron |
視個人需求 |
執行在 crontab 設定的時間沒有執行到的工作 |
| auditd |
視個人需求 |
稽核系統 /var/log/audit/audit.log,若 auditd 未執行中則稽核訊息會寫入 /var/log/messages (配合 SELinux) |
| iptables |
視個人需求 |
使系統支援 IPTables Filrewall |
| irqbalance |
視個人需求 |
使系統支援多個 CPU 環境當系統中斷請求時進行負載平衡的程序,所以單 CPU 的機器就不需要 |
| lvm2-monitor |
視個人需求 |
使系統支援 Logical Volume Manager 邏輯磁區 |
| mcstrans |
視個人需求 |
主要用於配合 SELinux 服務 |
| mdmonitor |
視個人需求 |
使系統支援 RAID 相關程序 |
| microcode_ctl |
視個人需求 |
使系統支援 Intel IA32 CPU 特色,所以 AMD CPU 不需要 |
| netfs |
視個人需求 |
Network File System Mounter 網路掛載系統 (如 NFS、Samba、NCP) |
| restorecond |
視個人需求 |
使系統支援 SELinux 監控檔案狀態 |
| smartd |
視個人需求 |
使系統支援檢查硬碟狀態 (Hardware RAID 要改設定檔) |
| sendmail |
視個人需求 |
使系統支援 Sendmail |
| xfs |
視個人需求 |
使系統支援 X Window 字型 |
| |
| crond |
啟動 |
/etc/cron.* 排程服務 |
| kudzu |
啟動 |
使系統每次開機會都自動執行硬體偵測 |
| network |
啟動 |
使系統支援網卡 |
| readahead_early |
啟動 |
使系統再啟動時預先將相關檔案讀到記憶體內來加快啟動速度 |
| sshd |
啟動 |
使系統支援 SSH Service |
| syslog |
啟動 |
使系統支援 System Log Service |
amd:自动安装NFS(网络文件系统)守侯进程
apmd:高级电源管理
Arpwatch:记录日志并构建一个在LAN接口上看到的以太网地址和IP地址对数据库
Autofs:自动安装管理进程automount,与NFS相关,依赖于NIS
Bootparamd:引导参数服务器,为LAN上的无盘工作站提供引导所需的相关信息
crond:Linux下的计划任务
Dhcpd:启动一个DHCP(动态IP地址分配)服务器
Gated:网关路由守候进程,使用动态的OSPF路由选择协议
Httpd:WEB服务器
Inetd:支持多种网络服务的核心守候程序
Innd:Usenet新闻服务器
Linuxconf:允许使用本地WEB服务器作为用户接口来配置机器
Lpd:打印服务器
Mars-nwe:mars-nwe文件和用于Novell的打印服务器
Mcserv:Midnight命令文件服务器
named:DNS服务器
netfs:安装NFS、Samba和NetWare网络文件系统
network:激活已配置网络接口的脚本程序
nfs:打开NFS服务
nscd:nscd(Name Switch Cache daemon)服务器,用于NIS的一个支持服务,它高速缓存用户口令和组成成员关系
portmap:RPC portmap管理器,与inetd类似,它管理基于RPC服务的连接
postgresql:一种SQL数据库服务器
routed:路由守候进程,使用动态RIP路由选择协议
rstatd:一个为LAN上的其它机器收集和提供系统信息的守候程序
ruserd:远程用户定位服务,这是一个基于RPC的服务,它提供关于当前记录到LAN上一个机器日志中的用户信息
rwalld:激活rpc.rwall服务进程,这是一项基于RPC的服务,允许用户给每个注册到LAN机器上的其他终端写消息
rwhod:激活rwhod服务进程,它支持LAN的rwho和ruptime服务
sendmail:邮件服务器sendmail
smb:Samba文件共享/打印服务
snmpd:本地简单网络管理候进程
squid:激活代理服务器squid
syslog:一个让系统引导时起动syslog和klogd系统日志守候进程的脚本
xfs:X Window字型服务器,为本地和远程X服务器提供字型集
xntpd:网络时间服务器
ypbind:为NIS(网络信息系统)客户机激活ypbind服务进程
yppasswdd:NIS口令服务器
ypserv:NIS主服务器
gpm:管鼠标的
identd:AUTH服务,在提供用户信息方面与finger类似
Linux各项系统开机服务的功能是什么?有哪些可以关掉?
Linux在启动时要启动很多系统服务,它们向本地和网络用户提供了 Linux的系统功能接口,直接面向应用程序和用户。但是,开启不必要或有漏洞的服务则会 给操作系统带来安全和性能上的影响。下面我们以BluePoint Linux 2.0的开机服务为例,列表说明各项服务的功能。
alsasound
Alsa声卡驱动程序支持。Alsa声卡驱动程序本来是为了 一种声卡Gravis UltraSound(GUS)而写的,该程序被证 明很优秀,于是作者就开始为一般的声卡写 驱动程序。 Alsa和OSS/Free 及OSS/Linux兼容,但是有自己的接 口,甚至比OSS优秀。
amd
运行automount精灵程序,该精灵在必要时自动安装一些 本地设备和NFS文件系统。
apmd
apmd用来监视系统用电状态,并将相关信息通过syslogd 写入日志。也可以用来在电源不足时关机。
arpwatch
该程序主要用来维护以太网物理地址和IP地址的对应关系。
atalk
AppleTalk精灵程序。注意不要在后台运行该程序,该程 序的数据结构必须在运行其他进程前先花一定时间初始化。
atd
运行用户用At命令调度的任务。也在系统负荷比较低时 运行批处理任务。
autofs
当您需要时自动转载文件系统,而当您不需要时自动卸载。
bootparamd
该服务允许老的Sun工作站从Linux网络启动,它和rarp 现在很少使用,基本上被bootp和dhcp取代了。
crond
cron是Unix下的一个传统程序,该程序周期地运行用户 调度的任务。比起传统的Unix版本,Vixie版本添加了不 少属性,而且更安全,配置更简单。
dhcpd 该精灵提供了对动态主机控制协议(Dynamic Host Control Protocol)的访问支持。
gated
gated通过一个数据库提供了网络路由功能支持。它支持 各种路由协议,包括RIP版本1和2、DCN HELLO协议、 OSPF版本2以及EGP版本2到4。
gpm
gpm为文本模式下的Linux程序如mc(Midnight Commander)提供了鼠标的支持。它也支持控制台下鼠标 的拷贝,粘贴操作以及弹出式菜单。
httpd
http是著名的www服务器,可用来提供HTML文件以 及CGI动态内容服务。
inetd
因特网操作服务程序。监控网络对各种它管理的服务的需 求,并在必要的时候启动相应的服务程序。通常,inetd 管理的程序有telnet、ftp、rsh和rlogin。 关闭inetd也就 关闭了这些由它管理的服务。
innd
inn是最流行的用户组新闻服务器。它允许您建立起本地 新闻服务器。配置有一定的难度,可以先阅读/usr/doc/ inn*文档获得帮助。
keytable 该程序的功能是转载您在/etc/sysconfig/keyboards里说 明的键盘映射表,该表可以通过kbdconfig工具进行选 择。您应该使该程序处于激活状 态。
ldap
LDAP代表Lightweight Directory Access Protocol, 实现了目录访问协议的行业标准。
linuxconf
linuxconf是Linux下的一个有效的系统配置工具,该服 务允许远程运行。
lpd
lpd是系统打印守护程序,负责将lpr等程序提交给打印 作业。
mcserv
Midnight Commander服务进程允许远程机器上的用户 通过Midnight Commander文件管理器操作本机文件。服 务进程用PAM来验证用户,需要给出“用 户名/口令” 以通过验证。
mysql 一个快速高效可靠的轻型SQL数据库引擎。
named 域名服务器,将Internet主机名解析为点分的IP地址。
netfs 负责装载/卸载NFS、Samba、NCP(Netware)文件系统。
network 激活/关闭启动时的各个网络接口。
nfs
NFS是一个流行的基于TCP/IP网络的文件共享协议。该 服务提供了NFS文件共享服务,具体的配置在/etc/ exports文件里。
nscd
该服务负责密码和组的查询,并且缓冲查询结果。如果您 的系统有比较慢的服务(如NIS和NIS+),则应该启动该 服务。
pcmcia pcmcia 主要用于支持笔记本电脑。
portmap portmap 用来支持RPC连接,RPC被用于NFS以及NIS 等服务。
postgresql PostgreSQL 关系数据库引擎。
proftpd proftpd 是Unix下的一个配置灵活的ftp守护程序。
radvd 路由广播程序。
random
保存和恢复系统的高质量随机数生成器,这些随机数是系 统一些随机行为提供的。
routed
该守护程序支持RIP协议的自动IP路由表维护。RIP主要 使用在小型网络上,大一点的网络就需要复杂一点的协议。
rstatd Rstat协议允许网络上的用户获得同一网络上各机器的性能 参数。
rusersd 该服务使网络用户可以定位同一网络上的其他用户。
rwalld
Rwall协议允许远程用户向在同一系统中活跃着的终端发送 消息,类似wall的本地行为。
rwhod
允许远程用户获得运行rwho精灵的机器上所有已登录用户 的列表,与finger类似。
sendmail 大名鼎鼎的邮件服务器。
smb 启动和关闭smbd和nmbd精灵程序以提供SMB网络服务。
snmpd 简单网络管理协议(SNMP)的守护精灵。
syslog
syslog是操作系统提供的一种机制,守护程序通常使用这 种机制将各种信息写到各个系统日志文件。通常应该启动 该服务。
xfs X的字体服务器。
ypbind NIS/YP的客户端守护程序。如果您需要使用NIS/YP机 器,请启动这项服务,否则,关闭这项服务。
yppasswd
让NIS用户能够修改密码。运行在NIS域的服务器上。客 户端程序同样也叫yppasswd。
ypserv
标准NIS/YP网络协议的一个实现。允许主机名,用户名 和其他信息分布于网络各端。运行在NIS服务器上,客户 端不需要。
注:使用chkconfig --list 查看当前系统的所有服务
使用chkconfig <name> on|off来打开或者关闭某些服务
posted @ 2011-01-05 14:21 空空色色 阅读(150) 评论(0)
编辑
1.定制启动画面
a)linux启动画面分为两种,grub使用的背景图片,以及kernel启动时的图片(即一般在启用linux framebuffer设备时出现的小企鹅画面,一般系统有几个CPU,就会出现几个小企鹅)
首先定制grub的背景,要求图像尺寸为640*480(没试过其他尺寸), 而且主机已安装了convert开源图像处理工具。
例如准备了一张图像为splash.bmp,
执行:
convert -geometry 640x480 -colors 14 splash.bmp splash.xpm /*背景要求640x480的尺寸,以及14色*/
gzip -9 splash.xpm
cp splash.xpm.gz /boot/grub
注意备份原有的splash.xpm.gz
再次启动,grub的背景图片已被更改,需要注意的是grub的配置menu.cfg中需要命令行支持splash画面
b)
linux kernel的启动logo存放于KERNEL_PATH/drivers/video/logo/logo_linux_cult224.ppm
是被编译到内核的,所以不能简单的替换就改变原有的logo,按以下命令制作logo_linux_cult224.ppm
bmptopnm logo.bmp > logo_linux_cult224.pnm /*格式转换*/
pnmquant 224 logo_linux_cult224.pnm > logo_linux_cult224.pnm /*将图像改为224色*/
pnmtopnm logo_linux_cult224.pnm > logo_linux_cult224.ppm /*将图像转存为ppm格式*/
替换新内核中原有的logo_linux_cult224.ppm,注意备份原有的企鹅logo_linux_cult224.ppm。
内核编译后,且以framebuffer方式启动新内核,此时企鹅图标就变成了自定义的LOGO(注意LOGO图像的尺寸不能大于framebuffer的尺寸)
但是在启动中,logo上会有光标在闪烁,如果需要将光标去除(提示console的光标也会消失),将内核中的KERNEL_PATH/drivers/video/console/fbcon.c中的fb_flashcursor和fbcon_sursor函数体置空。重新编译安装内核即可。
2.内核编译
内核的编译需要依照实际的硬件配置,否则,对不明确的地方全选即可。需要注意的是:在2.6.xx版的内核中在配置文件中有部分配置需要手动修正:
CONFIG_SYSFS_DEPRECATED=y
CONFIG_SYSFS_DEPRECATED_V2=y
否则在使用LVM的linux系统下,内核编译成功但是会提示找不到VolGroup00等错误,并直接导致内核启动失败,文件系统挂载出错。
另外在2.6.36的内核中(可能此前的内核也存在这个问题),即使用intel和mavell以太网硬件的平台上,编译内核后会导致网络驱动加载失败,即找不到eth0和eth1设备。
这个问题和LVM的问类似,首先查看网卡设备信息:
lspci
结果会列出pci上所有的硬件设备信息,如ethernet,usb等,找到对应的以太网调制器。
cat /etc/modprobe.conf
找出ethx对应的驱动程序(如果系统在内核升级前正常,而升级后网络不正常了,那可以在这里找到此前的有效驱动名称)
在新内核下/lib/modules/2.6.xx/kernel/driver/net下如果能找到这些驱动,那么说明问题不出在驱动层,就可以不用再重新编译内核。否者查看新内核目录的.config配置文件
找到CONFIG_E1000E,和CONFIG_SKY2关键字,如果是“未设置”状态,将这两行加上:
CONFIG_E1000E=m
CONFIG_SKY2=m
保存后退出
make clean
make all
make modules_install
make install
修改grub的启动顺序使之选用新内核而后reboot
3.initrd定制
内核编译安装后,重启可能会遇到类似insmod xxxx.ko error: xxxx.ko exist的错误
这是因为在生存initrd.img文件时,打包软件重复的引入了某些驱动模块
按以下步骤解压initrd.img
新建一个目录用于存放解压的initrd
mkdir initrd
cd initrd
cp /boot/initrd.img initrd.img.gz
gunzip initrd.img.gz
cpio -idcmv < initrd.img
此时initrd目录下生成了诸多文件,其他不理会,编辑init文件,删除其中的重复项,保存并退出
删除旧的压缩文件
rm initrd.img
然后执行以下命令生成新的initrd.img
find . | cpio -c -o > initrd.img
gzip -9 initrd.img
mv initrd.img.gz inird.img
使用新的initrd.img替换boot目录下的对应文件,使用时注意initrd.img的具体文件名,中途勿随意更改中间结果的名称。
posted @ 2011-01-05 14:16 空空色色 阅读(662) 评论(0)
编辑

2008年7月21日
Linux NAT服务器支持UPnP方法
一、什么是UPnP
1. UPnP简介
--------------
UPnP(Universal Plug and Play)技术对即插即用进行了扩展,它简化了家庭或企业中智能设备的联网过程。在结合了UPnP技术的设备以物理形式连接到网络中之后,它们可以通过网络自动彼此连接在一起,而且连接过程无需用户的参与
UPnP规范基于TCP/IP协议和针对设备彼此间通讯而制订的其它Internet协议。这就是它之所以被称作"通用(Universal)"的原因所在--UPnP技术不依赖于特定的设备驱动程序,而是使用标准的协议。UPnP设备可以自动配置网络地址,宣布它们在某个网络子网的存在,以及互相交换对设备和服务的描述。基于Windows XP的计算机可以充当一个UPnP控制点,通过程序界面对设备进行发现和控制。
如果与以前的即插即用相比,这种技术似乎并不具有什么革命性的意义。在
操作系统中增加即插即用技术使得在单个计算机上安装、配置和添加外设的工作变得更容易了。但是UPnP为家庭用户或者小型办公环境中的非专业用户所带来的是一道更加美味的"大餐",他们可以利用UPnP玩多人游戏,进行实时通信(Internet电话,电话会议)以及使用类似Windows XP的远程协助这样的其它技术。
2. NAT 穿越技术
------------------
NAT穿越技术允许网络应用程序对它们是否位于一个具有UPnP能力的NAT设备之后进行检测。然后,这些程序将获得共享的全球可路由IP地址,并且配置端口映射以将来自NAT外部端口的数据包转发到应用程序使用的内部端口上--所有这一切都是自动完成的,用户无需手动映射端口或者进行其它工作。NAT穿越技术允许网络设备或者点对点应用程序通过动态开启和闭合与外部服务之间的通信端口穿过NAT网关与外界通信。
二、在Linux中部署UPnP支持
我们假设该Linux的内核版本是2.4.x,使用拨号
上网,外网接口是ppp0,内网接口是eth0,并且已经启用iptables设定了 NAT。
在Linux中部署UPnP主要使用2个软件的配合:UPnP SDK for Linux和LinuxIGD。
下载地址:
UPnP SDK for Linux: http://sourceforge.net/projects/upnp/
LinuxIGD: http://linux-igd.sourceforge.net/
注意:要下载upnpsdk-1.0.4.tar.gz,1.0.4以上的版本不能和LinuxIGD很好的协同工作!
A. 安装:
----------
1. 解包UPnP SDK
# tar xzvf upnpsdk-1.0.4.tar.gz
2. 修改源代码
为了能够使Windows MSN Messenger在UPnP下正常通讯,所以必须修改源代码:
# cd upnpsdk-1.0.4
# vi src/ssdp/ssdplib.c
将第406行的:
SelfAddr.sin_addr.s_addr = inet_addr(SSDP_IP);
改为:
SelfAddr.sin_addr.s_addr = htonl(INADDR_ANY);
3. 编译安装UPnP SDK
#agt-get install uuid-dev
# make
# make install
4. 解包Linux-IGD
# tar xzvf linuxigd-0.92.tgz
5. 编译安装Linux-IGD
# cd linux-igd
# make
# make install
B. 配置
--------
1. 增加多播路由
# route add -net 239.0.0.0 netmask 255.0.0.0 eth1
2. 为iptables建议一个软链接
# cd /usr/sbin
# ln -s /sbin/iptables ./
启动UPnP (eth0为外网网卡,eth1为内网网卡)
# upnpd eth0 eth1
诊断UPnP运行状态
# tail /var/log/messages
如果能够看到:
Dec 14 16:01:49 doorway -- MARK --
Dec 14 16:02:15 doorway upnpd:
The Linux UPnP Internet Gateway Device Ver 0.92 by Dime (dime@gulfsales.com)
Dec 14 16:02:15 doorway upnpd:
Special Thanks for Intel's Open Source SDK and original author Genmei Mori's work.
则说明UPnP已经成功启动。
C. 测试
--------
以支持UPnP的P2P网络电视PPLive为例,在PPLive中打开UPnP支持选项,然后连接一个频道。
在Linux中执行:
# tail /var/log/debug -f
如果能看到:
Dec 14 16:56:33 doorway upnpd: AddPortMap: RemoteHost: (null) Prot: 17 ExtPort: 3226 Int: 10.0.0.2.3226
Dec 14 16:56:33 doorway upnpd: AddPortMap: RemoteHost: (null) Prot: 6 ExtPort: 3226 Int: 10.0.0.2.3226
Dec 14 16:56:33 doorway upnpd: AddPortMap: RemoteHost: (null) Prot: 6 ExtPort: 3156 Int: 10.0.0.2.3156
Dec 14 16:56:33 doorway upnpd: AddPortMap: RemoteHost: (null) Prot: 6 ExtPort: 3156 Int: 10.0.0.2.3156
则说明PPLive已经向UPnP请求进行端口映射了。只要看到这样的字样,就说明UPnP已经完全工作起来了。
posted @ 2008-07-21 20:36 空空色色 阅读(634) 评论(0)
编辑
UPNP的全称是
Universal plug-and-play( 通用即插即用).UPnP 是针对智能家电、无线设备以及各种外观尺寸的个人电脑的普遍对等(peer-to-peer)网络连接而设计的一种架构。它旨在为家庭、小型企业、公共场所中或连接到互联网的ad-hoc 网或未管理网络提供易于使用、灵活且基于标准的连接。(引自
这里.)
我们这里用到的自动端口映射只是UPNP的一个小应用。按照UPNP的相关规范,UPNP网络的第0步是寻址(获得一个IP地址,在我要解决的问题中这不是一个问题。)
第1步是发现,控制点在网上搜索感兴趣的设备,而设备向网络中的控制点宣告其服务。对于自动端口映射来说就是发现带UPNP功能的路由器。
发现这个过程主要有两步。第一,使用数据报套接字向239.255.255.250:1900,发送一条多播请求,格式如下
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN:"ssdp:discover"
MX:3
ST:UPnP:rootdevice
这个多播请求的含义如下:M-SEARCH SSDP协议定义的搜索请求方法。HOST必须是这个多播地址。MAN的值也必须是"ssdp:discover" 不可少了双引号。MX的含义是最长等待时间,可以自己设置。ST表示search target 搜索目标。我们在这里用找根设备。另外在编程中我们要在每一行后面加上"rn" 表示换行。(详见源码 UPNPNAT.discovery()).
第二步,如果你的网络存在一个UPNP设备的话,为了被找到,设备必须向发送查找请求的多播通道的源 IP 地址与端口发送响应信息。所以你可以从239.255.255.250:1900这个地址接收到响应消息。类似下面的消息。
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=100
DATE: Sun, 15 Jan 2006 06:51:02 GMT
EXT:
LOCATION: http://192.168.14.1:1900/igd.xml
SERVER: TP-LINK Wireless Router WR541G/5, UPnP/1.0
ST: upnp:rootdevice
USN:uuid:upnp-InternetGatewayDevice-192168141678900001::upnp:rootdevice
接下来我们要从里面获得我们要的消息。首先,我们必须找到" 200 OK ",说明没有错误发生,否则一切免谈。接着,我们要找到LOCATION项,获得设备描述URL。(程序中的处理归根到底就是一个子字符的查找。)
到这里,我们的第一步“发现”完成。
第2步是描述。在第1步中我们往往能获得一个设备的描述URL,在第2步中我们要通过一个URL,下载一个XML文件。并从中找到有关设备的类型,服务类型,控制URL,事件触发URL等。
我们同样分两步进行,首先下载设备描述文件。(请看源码中UPNPNAT::get_description()函数)
1.解析描述文件的URL,获得主机(host)、端口(port)、路径(path).(parseUrl函数)
2.连接到host:port (tcp_connect 函数)
3.构造类似
GET path HTTP/1.1
Host: host:port
的信息(第二行下要一个空行),并通过刚才的TCP 套接字,发送到路由器。(sprintf ,send 函数).
4.接收数据,我使用flag为 MSG_WAITALL的recv函数,函数一直阻塞直到数据全部读完。 数据最终保存在std::string description_info中。
我想通过浏览器下载这个文件的过程是类似的吧。
然后,解析这个XML文件。(请看
源码 中UPNPNAT:: parser_description()函数)
我们找到"root"的"deviceType"是"urn:schemas-upnp-org:device:InternetGatewayDevice:1"的"device" childNode ,获得这个"device"的"deviceList",记为A。
找到A的"deviceType"是"urn:schemas-upnp-org:device:WANDevice:1"的"device" childNode ,获得这个"device"的"deviceList",记为B。
找到B的"deviceType"是"urn:schemas-upnp-org:device:WANConnectionDevice:1"的"device" childNode ,获得这个"device"的"serviceList",记为C。
找到C的"serviceType"是"urn:schemas-upnp-org:service:WANIPConnection:1" 或"urn:schemas-upnp-org:service:WANPPPConnection:1" 的"service" childNode ,记为D.
获得D的"controlUrl"保存在std::string control_url中。
但是这里获得control_url一般为相对URL,所以要从"root"下面,找到"URLBase"的值,(如果是空,则用describe_url的"htpp://xxx.xxx.xxx.xxx:xxxx"部分代替.)
最后在相对的control_url前加上URLBasr 获得完整的control_url.
至此,第二步“获得控制URL”完成。
第3步是控制。通过第2步获得的控制URL,通过向其发送控制消息(同样用XML描述)来实现某些功能。对于自动端口映射来说就是查看、增加、删除等。
在这里我先把各种控制信息的格式说明一下。(下面的rn都是表示换行,我输入不了反斜杠。)
- 增加端口映射。 "AddPortMapping"
- "<NewRemoteHost></NewRemoteHost>rn" "<NewExternalPort>ExternalPort</NewExternalPort>rn" "<NewProtocol>Protocol</NewProtocol>rn" "<NewInternalPort>InternalPort</NewInternalPort>n"
"<NewInternalClient>InternalClient</NewInternalClient>rn"
"<NewEnabled>1</NewEnabled>rn"
"<NewPortMappingDescription>PortMappingDescription" "</NewPortMappingDescription>rn"
"<NewLeaseDuration>LeaseDuration</NewLeaseDuration>rn"
- 删除端口映射 "DeletePortMapping"
- "<NewRemoteHost></NewRemoteHost>rn" "<NewExternalPort>ExternalPort</NewExternalPort>rn" "<NewProtocol>Protocol</NewProtocol>rn"
- 获得端口映射信息 "GetGenericPortMappingEntry"
- "<NewPortMappingIndex>PortMappingIndex</NewPortMappingIndex>" "<NewRemoteHost></NewRemoteHost>rn" "<NewExternalPort></NewExternalPort>rn" "<NewProtocol></NewProtocol>rn" "<NewInternalPort></NewInternalPort>rn" "<NewInternalClient></NewInternalClient>rn" "<NewEnabled>1</NewEnabled>rn" "<NewPortMappingDescription>" "</NewPortMappingDescription>rn" "<NewLeaseDuration></NewLeaseDuration>rn"
其中斜体部分需要在编程是填入的。ExternalPort 外部端口。InternalPort内部端口。这 两者一般就填映射的端口。Protocal 填TCP或UDP。InterClient 一般就是本地IP地址。PortMappingDescription 填写端口映射的描述,比如什么程序建立了这个端口。LeaseDuration 是映射的持续时间,用0表示不永久。PortMappingIndex 是端口映射索引,路由上第几个映射。
我们再来看下面这个XML文档结构。
"<?xml version="1.0" encoding="utf-8"?>rn"
"<s:Envelope xmlns:s="
""http://schemas.xmlsoap.org/soap/envelope/" "
"s:encodingStyle="
""http://schemas.xmlsoap.org/soap/encoding/">rn"
"<s:Body>rn"
"<u:actionName xmlns:u="serviceType">rn"
"actionParams</u:actionName>rn"
"</s:Body>rn"
"</s:Envelope>rn"
我们在actionName 处填入"AddPortMapping" "DeletePortMapping" "GetGenericPortMappingEntry"。serviceType 处填入设备的服务类型。"urn:schemas-upnp-org:service:WANIPConnection:1"或"urn:schemas-upnp-org:service:WANPPPConnection:1"。actionParams 填入上面的各种控制信息。
最后在前面加上HTTP头。
"POST path HTTP/1.1rn"
"HOST: host:portrn"
"SOAPACTION:"serviceType#actionName"rn"
"CONTENT-TYPE: text/xml ; charset="utf-8"rn"
"Content-Length: contentLength rnrn"
path host port 意思很明显。contentLength面那个XML文档的长度。
然后连接到host:port,发送到整个信息即可完成控制
第4步事件触发和第5步展示在自动端口映射没用用到。有兴趣可以自己看文档。
posted @ 2008-07-21 20:22 空空色色 阅读(2409) 评论(0)
编辑

2008年7月16日
Universal Plug and Play
From Wikipedia, the free encyclopedia
Universal Plug and Play (UPnP) is a set of computer network protocols promulgated by the UPnP Forum. The goals of UPnP are to allow devices to connect seamlessly and to simplify the implementation of networks in the home (data sharing, communications, and entertainment) and corporate environments. UPnP achieves this by defining and publishing UPnP device control protocols built upon open, Internet-based communication standards.
The term UPnP is derived from plug-and-play, a technology for dynamically attaching devices directly to a computer.
[edit] Overview
The UPnP architecture allows peer-to-peer networking of PCs, networked appliances, and wireless devices. It is a distributed, open architecture based on established standards such as TCP/IP, UDP, HTTP and XML.
The UPnP architecture supports zero-configuration networking. A UPnP compatible device from any vendor can dynamically join a network, obtain an IP address, announce its name, convey its capabilities upon request, and learn about the presence and capabilities of other devices. DHCP and DNS servers are optional and are only used if they are available on the network. Devices can leave the network automatically without leaving any unwanted state information behind.
Other UPnP features include:
- Media and device independence
- UPnP technology can run on many media that support IP including Ethernet, FireWire, IR (IrDA), power lines (PLC) and RF (Bluetooth, Wi-Fi). No special device driver support is necessary; common protocols are used instead.
- User interface (UI) Control
- UPnP architecture enables vendor control over device user interface and interaction using the web browser.
- Operating system and programming language independence
- Any operating system and any programming language can be used to build UPnP products. UPnP does not specify or constrain the design of an API for applications running on control points; OS vendors may create APIs that suit their customer's needs. UPnP enables vendor control over device UI and interaction using the browser as well as conventional application programmatic control.
- Programmatic control
- UPnP architecture also enables conventional application programmatic control.
- Extensibility
- Each UPnP product can have device-specific services layered on top of the basic architecture.
The foundation for UPnP networking is IP addressing. Each device must have a Dynamic Host Configuration Protocol (DHCP) client and search for a DHCP server when the device is first connected to the network. If no DHCP server is available, that is, the network is unmanaged, the device must assign itself an address. If during the DHCP transaction, the device obtains a domain name, for example, through a DNS server or via DNS forwarding, the device should use that name in subsequent network operations; otherwise, the device should use its IP address.
[edit] Protocol
[edit] Discovery
Given an IP address, the first step in UPnP networking is discovery. When a device is added to the network, the UPnP discovery protocol allows that device to advertise its services to control points on the network. Similarly, when a control point is added to the network, the UPnP discovery protocol allows that control point to search for devices of interest on the network. The fundamental exchange in both cases is a discovery message containing a few, essential specifics about the device or one of its services, for example, its type, identifier, and a pointer to more detailed information. The UPnP discovery protocol is based on the Simple Service Discovery Protocol (SSDP).
[edit] Description
The next step in UPnP networking is description. After a control point has discovered a device, the control point still knows very little about the device. For the control point to learn more about the device and its capabilities, or to interact with the device, the control point must retrieve the device's description from the URL provided by the device in the discovery message. The UPnP description for a device is expressed in XML and includes vendor-specific, manufacturer information like the model name and number, serial number, manufacturer name, URLs to vendor-specific web sites, etc. The description also includes a list of any embedded devices or services, as well as URLs for control, eventing, and presentation. For each service, the description includes a list of the commands, or actions, to which the service responds, and parameters, or arguments, for each action; the description for a service also includes a list of variables; these variables model the state of the service at run time, and are described in terms of their data type, range, and event characteristics.
[edit] Control
The next step in UPnP networking is control. After a control point has retrieved a description of the device, the control point can send actions to a device's service. To do this, a control point sends a suitable control message to the control URL for the service (provided in the device description). Control messages are also expressed in XML using the Simple Object Access Protocol (SOAP). Like function calls, in response to the control message, the service returns any action-specific values. The effects of the action, if any, are modeled by changes in the variables that describe the run-time state of the service.
[edit] Event notification
The next step in UPnP networking is event notification, or "eventing". A UPnP description for a service includes a list of actions the service responds to and a list of variables that model the state of the service at run time. The service publishes updates when these variables change, and a control point may subscribe to receive this information. The service publishes updates by sending event messages. Event messages contain the names of one or more state variables and the current value of those variables. These messages are also expressed in XML and formatted using the General Event Notification Architecture (GENA). A special initial event message is sent when a control point first subscribes; this event message contains the names and values for all evented variables and allows the subscriber to initialize its model of the state of the service. To support scenarios with multiple control points, eventing is designed to keep all control points equally informed about the effects of any action. Therefore, all subscribers are sent all event messages, subscribers receive event messages for all "evented" variables that have changed, and event messages are sent no matter why the state variable changed (either in response to a requested action or because the state the service is modeling changed).
[edit] Presentation
The final step in UPnP networking is presentation. If a device has a URL for presentation, then the control point can retrieve a page from this URL, load the page into a web browser, and depending on the capabilities of the page, allow a user to control the device and/or view device status. The degree to which each of these can be accomplished depends on the specific capabilities of the presentation page and device.
[edit] UPnP AV (Audio and Video) standards
UPnP AV stands for UPnP Audio and Video, and is a grouping within the UPnP standards supervised by the DLNA (Digital Living Network Alliance), (formerly: Digital Home Working Group), which is a forum of vendors and manufacturers who work in the home entertainment industry, and offer a "DLNA CERTIFIED™" branding for those products which follow their Networked Device Interoperability Guidelines. The DLNA forum members "share a vision of a wired and wireless interoperable network of Personal Computers (PC), Consumer Electronics (CE) and mobile devices in the home enabling a seamless environment for sharing and growing new digital media and content services," and "DLNA is focused on delivering an interoperability framework of design guidelines based on open industry standards to complete the cross-industry digital convergence". On 12 July 2006 the UPnP Forum announced the release of 'Enhanced AV Specifications', this release was version 2 of the UPnP Audio and Video specifications (UPnP AV v2), with new MediaServer version 2.0 and MediaRenderer version 2.0 classes. These enhancements are created by adding capabilities to the UPnP AV MediaServer and MediaRenderer device classes that allow a higher level of interoperability between MediaServers and MediaRenderers from different manufacturers. Some of the early devices complying with these standards were marketed by Philips under the Streamium brand name. .
[edit] UPnP AV components
- UPnP MediaServer DCP - which is the UPnP-server (a 'slave' device) that shares/streams media-data (like audio/video/picture/files) to UPnP-clients on the network.
- UPnP MediaServer ControlPoint - which is the UPnP-client (a 'master' device) that can auto-detect UPnP-servers on the network to browse and stream media/data-files from them.
- UPnP MediaRenderer DCP - which is a 'slave' device that can render content.
- UPnP RenderingControl DCP - control MediaRenderer settings; volume, brightness, RGB, sharpness, and more).
- UPnP Remote User Interface (RUI) client/server - which sends/receives control-commands between the UPnP-client and UPnP-server over network, (like record, schedule, play, pause, stop, etc.).
- QoS (Quality of Service) - is an important (but not mandatory) service function for use with UPnP AV (Audio and Video). QoS (Quality of Service) refers to control mechanisms that can provide different priority to different users or data flows, or guarantee a certain level of performance to a data flow in accordance with requests from the application program. Since UPnP AV is mostly to deliver streaming media that is often near real-time or real-time audio/video data which it is critical to be delivered within a specific time or the stream is interrupted. QoS (Quality of Service) guarantees are especially important if the network capacity is limited, for example public networks, like the internet.
- QoS (Quality of Service) for UPnP consist of Sink Device (client-side/front-end) and Source Device (server-side/back-end) service functions. With classes such as; Traffic Class that indicates the kind of traffic in the traffic stream, (for example, audio or video). Traffic Identifier (TID) which identifies data packets as belonging to a unique traffic stream. Traffic Specification (TSPEC) which contains a set of parameters that define the characteristics of the traffic stream, (for example operating requirement and scheduling). Traffic Stream (TS) which is a unidirectional flow of data that originates at a source device and terminates at one or more sink device(s).
[edit] NAT traversal
One solution for NAT (Network Address Translation) traversal, called the Internet Gateway Device (IGD) Protocol, is implemented via UPnP. Many routers and firewalls expose themselves as Internet Gateway Devices, allowing any local UPnP controller to perform a variety of actions, including retrieving the external IP address of the device, enumerate existing port mappings, and adding and removing port mappings. By adding a port mapping, a UPnP controller behind the IGD can enable traversal of the IGD from an external address to an internal client.
[edit] Problems with UPnP
[edit] Lack of Authentication
The UPnP protocol does not implement any authentication, so UPnP device implementations must implement their own authentication mechanisms, or implement the Device Security Service.[2] Unfortunately, many UPnP device implementations lack authentication mechanisms, and by default assume local systems and their users are completely trustworthy.[3][4] Most notably, Routers and firewalls running the UPnP IGD protocol are vulnerable to attack since the framers of the UPnP implementation omitted to add any standard authentication method.
For example, Adobe Flash programs are capable of generating HTTPU (HTTP over UDP) requests. This allows a router implementing the UPnP IGD protocol to be controlled by a malicious web site when someone with a UPnP-enabled router simply visits that web site.[5] The following changes can be made silently by code embedded in an Adobe Flash object hosted on a malicious website[6]:
- Port forward internal services (ports) to the router external facing side (i.e. expose computers behind a firewall to the internet)
- Port forward the router's web administration interface to the external facing side
- Port forwarding to any external server located on the Internet, effectively allowing an attacker to attack an Internet host via the router, while hiding their IP address
- Change DNS server settings so that when victims believe they are visiting a particular site (such as an on-line bank), they are redirected to a malicious website instead.
- Change the DNS server settings so that when a victim receives any software updates (from a source that isn't properly verified via some other mechanism, such as a checking a digital certificate has been signed by a trusted source), they download malicious code instead.
- Change administrative credentials to the router/firewall
- Change PPP settings
- Change IP settings for all interfaces
- Change WiFi settings
- Terminate connections
This only applies to the "firewall-hole-punching"-feature of UPnP; it does not apply when the IGD does not support UPnP or UPnP has been disabled on the IGD.[citation needed] Also, not all routers can have such things as DNS server settings altered by UPnP because much of the specification (including LAN Host Configuration) is optional for UPnP enabled routers[7].
[edit] Other Issues
- UPnP uses HTTP over UDP (known as HTTPU and HTTPMU for unicast and multicast), even though this is not standardized and is specified only in an Internet-Draft that expired in 2001. [1]
- UPnP does not have a lightweight authentication protocol, while the available security protocols are complex. As a result, some UPnP devices ship with UPnP turned off by default as a security measure.
[edit] Future developments
The standard DPWS is a candidate successor for UPnP. It solves many of the problems of UPnP. A DPWS client is included in Microsoft Windows Vista as part of the Windows Rally technologies.
Another alternative, NAT-PMP, is an IETF draft introduced by Apple Inc in 2005.
[edit] See also
[edit] References
- ^ "Web4CE (CEA 2014) for UPnP Remote UI (www.ce.org/standards)".
- ^ "Device Security and Security Console V 1.0".
- ^ "Shorewall firewall author on UPnP security". Retrieved on 2007-09-30.
- ^ "Linux-IDG authors on UPnP security". Retrieved on 2007-09-30.
- ^ "Flash UPnP attack".
- ^ "Flash UPnP Attack FAQ". gnucitizen.org (January 14, 2008).
- ^ "Internet Gateway Device (IGD) V 1.0". UPnP Forum (November 12, 2001).
[edit] External links
[edit] Documentation
[edit] Software
- UPnP Port Works (alias UPnPW) is a software implementation to configure UPnP devices via commandline.
- GUPnP is an object-oriented open source framework for creating UPnP devices and control points, written in C using GObject and libsoup.
- Portable SDK for UPnP Devices provides an API and open source code for building control points, devices, and bridges compliant with UPnP Device Architecture Specification v1.0 and support operating systems like Linux, *BSD, Solaris and others.
- Barracuda UPnP Device and Control Point SDK for embedded devices.
- Unplug n' Pray Utility to disable unnecessary UPnP servers running on home Windows machines.
- Coherence Some free DLNA/UPnP tools (MediaServer/MediaRender) with a python framework. Running on Linux/BSD/Windows
- BRisa BRisa is written in Python for Internet Tablet OS or other Unix platforms. It enables to create MediaServer/MediaRenderer devices allowing users to share and search content from UPnP A/V devices. It will offer a plugin architecture enabling new services such as Flickr to be added as UPnP services.
- J. River Media Center includes a UPnP server (aka UPnP Device) for its library.
posted @ 2008-07-16 17:17 空空色色 阅读(691) 评论(0)
编辑

2007年11月2日
虽然把这类题目归为一个大类,但他们本身之间却绝少相同之处。每个题目都需要你打破思维的常规来回答。稍有不慎,就可能落入圈套。
例题1:你让工人为你工作7天,给工人的回报是一根金条。金条平分成相连的7段,你必须在每天结束时给他们一段金条,如果只许你两次把金条弄断,你如何给你的工人付费?
小蒲(现在微创工作,去年遭遇这道试题):这道试题相对其它一些微创考题还是简单的,可仍然把我弄得头大。当时我是这样做这道题的。两次弄断就应分成三份,我把金条分成1/7、2/7和4/7三份。这样,第1天我就可以给他1/7;第2天我给他2/7,让他找回我1/7;第3天我就再给他1/7,加上原先的2/7就是3/7;第4天我给他那块4/7,让他找回那两块1/7和2/7的金条;第5天,再给他1/7;第6天和第2天一样;第7天给他找回的那个1/7。
例题2:现在小明一家过一座桥,过桥时候是黑夜,所以必须有灯。现在小明过桥要1秒,小明的弟弟要3秒,小明的爸爸要6秒,小明的妈妈要8秒,小明的爷爷要12秒。每次此桥最多可过两人,而过桥的速度依过桥最慢者而定,而且灯在点燃后30秒就会熄灭。问小明一家如何过桥?
参考答案:这类智力题目,其实是考察应聘者在限制条件下解决问题的能力。具体到这道题目来说,很多人往往认为应该由小明持灯来来去去,这样最节省时间,但最后却怎么也凑不出解决方案。但是换个思路,我们根据具体情况来决定谁持灯来去,只要稍稍做些变动即可:第一步,小明与弟弟过桥,小明回来,耗时4秒;第二步,小明与爸爸过河,弟弟回来,耗时9秒;第三步,妈妈与爷爷过河,小明回来,耗时13秒;最后,小明与弟弟过河,耗时4秒,总共耗时30秒,多么惊险!
专家意见:这类题目多出现于跨国企业的招聘面试中,对考察一个人的思维方式及思维方式转变能力有极其明显的作用,而据一些研究显示,这样的能力往往也与工作中的应变与创新状态息息相关。所以回答这些题目时,必须冲破思维定式,试着从不同的角度考虑问题,不断进行逆向思维,换位思考,并且把题目与自己熟悉的场景联系起来,切忌思路混乱。
现在开始出题来考考大家:
智力题:猜牌问题
简介: 这是一道经典的趣味逻辑题。
详细介绍:
S先生、P先生、Q先生他们知道桌子的抽屉里有16张扑克牌:红桃A、Q、4 黑桃J、8、4、2、7、3 草花K、Q、5、4、6 方块A、5。约翰教授从这16张牌中挑出一张牌来,并把这张牌的点数告诉 P先生,把这张牌的花色告诉Q先生。这时,约翰教授问P先生和Q 先生:你们能从已知的点数或花色中推知这张牌是什么牌吗? 于是,S先生听到如下的对话:P先生:我不知道这张牌。
Q先生:我知道你不知道这张牌。
P先生:现在我知道这张牌了。
Q先生:我也知道了。
听罢以上的对话,S先生想了一想之后,就正确地推出这张牌是什么牌。
请问:这张牌是什么牌?
经典智力题集锦
简介:看看你会多少?
详细介绍:
1、一个经理有三个女儿,三个女儿的年龄加起来等于13,三个女儿的年龄乘起来等于经理自己的年龄,有一个下属已知道经理的年龄,但仍不能确定经理三个女儿的年龄,这时经理说只有一个女儿的头发是黑的,然后这个下属就知道了经理三个女儿的年龄。请问三个女儿的年龄分别是多少?为什么?
2、有三个人去住旅馆,住三间房,每一间房$10元,于是他们一共付给老板$30,第二天,老板觉得三间房只需要$25元就够了于是叫小弟退回$5给三位客人,谁知小弟贪心,只退回每人$1,自己偷偷拿了$2,这样一来便等于那三位客人每人各花了九元,于是三个人一共花了$27,再加上小弟独吞了不$2,总共是$29。可是当初他们三个人一共付出$30那么还有$1呢?
3、有两位盲人,他们都各自买了两对黑袜和两对白袜,八对袜了的布质、大小完全相同, 而每对袜了都有一张商标纸连着。两位盲人不小心将八对袜了混在一起。他们每人怎样才能取回黑袜和白袜各两对呢?
4、有一辆火车以每小时15公里的速度离开洛杉矶直奔纽约,另一辆火车以每小时20公里的速度从纽约开往洛杉矶。如果有一只鸟,以30公里每小时的速度和两辆火车同时启动,从洛杉矶出发,碰到另一辆车后返回,依次在两辆火车来回飞行,直到两辆火车相遇,请问,这只小鸟飞行了多长距离?
5、你有两个罐子,50个红色弹球,50个蓝色弹球,随机选出一个罐子,随机选取出一个弹球放入罐子,怎么给红色弹球最大的选中机会?在你的计划中,得到红球的准确几率是多少?
经典面试题:外企趣味智力题
6、你有四个装药丸的罐子,每个药丸都有一定的重量,被污染的药丸是没被污染的重量+1.只称量一次,如何判断哪个罐子的药被污染了?
7、对一批编号为1~100,全部开关朝上(开)的灯进行以下*作:凡是1的倍数反方向拨一次开关;2的倍数反方向又拨一次开关;3的倍数反方向又拨一次开关……问:最后为关熄状态的灯的编号。
8、想象你在镜子前,请问,为什么镜子中的影像可以颠倒左右,却不能颠倒上下?
9、一群人开舞会,每人头上都戴着一顶帽子。帽子只有黑白两种,黑的至少有一顶。每个人都能看到其它人帽子的颜色,却看不到自己的。主持人先让大家看看别人头上戴的是什幺帽子,然后关灯,如果有人认为自己戴的是黑帽子,就打自己一个耳光。第一次关灯,没有声音。于是再开灯,大家再看一遍,关灯时仍然鸦雀无声。一直到第三次关灯,才有劈劈啪啪打耳光的声音响起。问有多少人戴着黑帽子?
10、两个圆环,半径分别是1和2,小圆在大圆内部绕大圆圆周一周,问小圆自身转了几周?如果在大圆的外部,小圆自身转几周呢?
11、 1元钱一瓶汽水,喝完后两个空瓶换一瓶汽水,问:你有20元钱,最多可以喝到几瓶汽水?
确定帽子颜色问题
简介:这是一道经典的趣味逻辑题。
详细介绍:
有3顶红帽子,4顶黑帽子,5顶白帽子。让10个人从矮到高站成一队,给他们每个人头上戴一顶帽子。每个人都看不见自己戴的帽子的颜色,却只能看见站在前面那些人的帽子颜色。(所以最后一个人可以看见前面9个人头上帽子的颜色,而最前面那个人谁的帽子都看不见。现在从最后那个人开始,问他是不是知道自己戴的帽子颜色,如果他回答说不知道,就继续问他前面那个人。假设最前面那个人一定会知道自己戴的是黑帽子。为什么?
称苹果问题
简介:不是脑筋急转弯,大家想想看。
详细介绍:
10个箱子,每个箱子10个苹果,其中一个箱子的苹果是9两/个,其他的都是1斤/个。 要求利用一个秤,只秤一次,找出那个装9两/个的箱子。
囚犯活命问题
简介:一道真正难倒亿人的智力题,这是微软的面试题。
详细介绍:
5个囚犯,分别按1-5号在装有100颗绿豆的麻袋抓绿豆,规定每人至少抓一颗,而抓得最多和最少的人将被处死,而且,他们之间不能交流,但在抓的时候,可以摸出剩下的豆子数。问他们中谁的存活几率最大?提示:
1,他们都是很聪明的人
2,他们的原则是先求保命,再去多杀人
3,100颗不必都分完
4,若有重复的情况,则也算最大或最小,一并处死
乒乓球问题
简介:该题由中华谣网站改造,有一定难度。
详细介绍:
假设排列着100个乒乓球,由两个人轮流拿球装入口袋,能拿到第100个乒乓球的人为胜利者。条件是:每次拿球者至少要拿1个,但最多不能超过5个,问:如果你是最先拿球的人,你该拿几个?以后怎么拿就能保证你能得到第100个乒乓球?
山羊的速度
简介:无
详细介绍:
卢姆教授说:“有一次我目击了两只山羊的一场殊死决斗,结果引出了一个有趣的数学问题。我的一位邻居有一只山羊,重54磅,它已有好几个季度在附近山区称王称霸。后来某个好事之徒引进了一只新的山羊,比它还要重出3磅。 开始时,它们相安无事,彼此和谐相处。可是有一天,较轻的那只山羊站在陡峭的山路顶上,向它的竞争对手猛扑过去,那对手站在土丘上迎接挑战,而挑战者显然拥有居高临下的优势。不幸的是,由于猛烈碰撞,两只山羊都一命呜呼了。
现在要讲一讲本题的奇妙之处。对饲养山羊颇有研究,还写过书的乔治·阿伯克龙比说道:“通过反复实验,我发现,动量相当于一个自20英尺高处坠落下来的30磅重物的一次撞击,正好可以打碎山羊的脑壳,致它死命。”如果他说得不错,那么这两只山羊至少要有多大的逼近速度,才能相互撞破脑壳?你能算出来吗?
酒肆老板娘的难题
简介:无
详细介绍:
据说有人给酒肆的老板娘出了一个难题:此人明明知道店里只有两个舀酒的勺子,分别能舀7两和11两酒,却硬要老板娘卖给他2两酒。聪明的老板娘毫不含糊,用这两个勺子在酒缸里舀酒,并倒来倒去,居然量出了2两酒,聪明的你能做到吗?
一道关于飞机加油的问题
简介:无
详细介绍:
已知: 每个飞机只有一个油箱, 飞机之间可以相互加油(注意是相互,没有加油机) 一箱油可供一架飞机绕地球飞半圈, 问题:为使至少一架飞机绕地球一圈回到起飞时的飞机场,至少需要出动几架飞机?(所有飞机从同一机场起飞,而且必须安全返回机场,不允许中途降落,中间没有飞机场)
难题
简介:这类题有一定难度,如果得不到答案,也不能说明什么。如果你想到了解题思路,那么答案马上就能出来。如果想不到思路,那么……就别想解出来了。
详细介绍:
1.你让工人为你工作7天,回报是一根金条,这个金条平分成相连的7段,你必须在每天结束的时候给他们一段金条。如果只允许你两次把金条弄断,你如何给你的工人付费? 2.有一辆火车以每小时15公里的速度离开北京直奔广州,同时另一辆火车每小时20公里的速度从广州开往北京。如果有一只鸟,以30公里每小时的速度和两辆火车同时启动,从北京出发,碰到另一辆车后就向相反的方向返回去飞,就这样依次在两辆火车之间来回地飞,直到两辆火车相遇。请问,这只鸟共飞行了多长的距离? 3.你有四个装药丸的罐子,每个药丸都有一定的重量,被污染的药丸是没被污染的药丸的重量+1。只称量一次,如何判断哪个罐子的药被污染了? 4.门外三个开关分别对应室内三盏灯,线路良好,在门外控制开关时候不能看到室内灯的情况,现在只允许进门一次,确定开关和灯的对应关系? 5.人民币为什么只有1、2、5、10的面值? 6.你有两个罐子以及50个红色弹球和50个蓝色弹球,随机选出一个罐子, 随机选出一个弹球放入罐子,怎么给出红色弹球最大的选中机会?在你的计划里,得到红球的几率是多少?
没有答案型
简介:这些题显然不是考你智力。而考的是你的反应能力。这种题大多数没有答案,但是要看你的反应喽!
详细介绍:
1.为什么下水道的盖子是圆的? 2.中国有多少辆汽车? 3.将汽车钥匙插入车门,向哪个方向旋转就可以打开车锁? 4.如果你要去掉中国的34个省(含自治区、直辖市和港澳特区及台湾省)中的任何一个,你会去掉哪一个,为什么? 5.多少个加油站才能满足中国的所有汽车? 6.想象你站在镜子前,请问,为什么镜子中的影象可以颠倒左右,却不能颠倒上下? 7.为什么在任何旅馆里,你打开热水,热水都会瞬间倾泻而出? 8.你怎样将Excel的用法解释给你的奶奶听? 9.你怎样重新改进和设计一个ATM银行自动取款机? 10.如果你不得不重新学习一种新的计算机语言,你打算怎样着手来开始? 11.如果你的生涯规划中打算在5年内受到奖励,那获取该项奖励的动机是什么?观众是谁? 12.如果微软告诉你,我们打算投资五百万美元来启动你的投资计划,你将开始什么样商业计划?为什么? 13.如果你能够将全世界的电脑厂商集合在一个办公室里,然后告诉他们将被强迫做一件事,那件事将是什么?
画线
简介:(3分钟-20分钟)
详细介绍:
在9个点上画10条直线,要求每条直线上至少有三个点?
称球
简介:(5分钟-1小时)
详细介绍:
12个球和一个天平,现知道只有一个和其它的重量不同,问怎样称才能用三次就找到那个球。13个呢?(注意此题并未说明那个球的重量是轻是重,所以需要仔细考虑)
问路
简介:(20秒-2分钟)
详细介绍:
一个岔路口分别通向诚实国和说谎国。来了两个人,已知一个是诚实国的,另一个是说谎国的。诚实国永远说实话,说谎国永远说谎话。现在你要去说谎国,但不知道应该走哪条路,需要问这两个人。请问应该怎么问?
称水
简介:(40秒-3分钟)回答
详细介绍:
如果你有无穷多的水,一个3公升的提捅,一个5公升的提捅,两只提捅形状上下都不均匀,问你如何才能准确称出4公升的水?
确定颜色
简介:(5秒-1分钟)回答
详细介绍:
你有一桶果冻,其中有黄色、绿色、红色三种,闭上眼睛抓取同种颜色的两个。抓取多少个就可以确定你肯定有两个同一颜色的果冻?
标题:海盗分宝石[智力测试题]
内容: 在美国,据说20分钟内能回答出这道题的人,平均年薪在8万美金以上。这是一道很有趣的推理题。
详细介绍:
在美国,据说20分钟内能回答出这道题的人,平均年薪在8万美金以上。这是一道很有趣的推理题。据统计,在美国20分钟内能回答出这道题的人,平均年薪在8万美金以上。 5个海盗抢到了100颗宝石,每一颗都一样的大小和价值连城。他们决定这么分: 1。抽签决定自己的号码(1,2,3,4,5) 2。首先,由1号提出分配方案,然后大家5人进行表决,当且仅当半数和超过半数的人同意时,按照他的提案进行分配,否则将被扔入大海喂鲨鱼。 3。如果1号死后,再由2号提出分配方案,然后大家4人进行表决,当且仅当半数和超过半数的人同意时,按照他的提案进行分配,否则将被扔入大海喂鲨鱼。 4。以次类推...... 条件: 每个海盗都是很聪明的人,都能很理智的判断得失,从而做出选择。 问题:第一个海盗提出怎样的分配方案才能够使自己的收益最大化。
算指针的重合次数
简介:(5分钟-15分钟)
详细介绍:
在一天的24小时之中,时钟的时针、分针和秒针完全重合在一起的时候有几次?都分别是什么时间?你怎样算出来的?
时间问题
简介:(这道题我当初想了一个小时)
详细介绍:
烧一根不均匀的绳,从头烧到尾总共需要1个小时。现在有若干条材质相同的绳子,问如何用烧绳的方法来计时一个小时十五分钟呢?
过桥问题
简介:无
详细介绍:
在漆黑的夜里,四位旅行者来到了一座狭窄而且没有护栏的桥边。如果不借助手电筒的话,大家是无论如何也不敢过桥去的。不幸的是,四个人一共只带了一只手电筒,而桥窄得只够让两个人同时过。如果各自单独过桥的话,四人所需要的时间分别是1、2、5、8分钟;而如果两人同时过桥,所需要的时间就是走得比较慢的那个人单独行动时所需的时间。问题是,如何设计一个方案,让这四人尽快过桥。
posted @ 2007-11-02 16:40 空空色色 阅读(551) 评论(4)
编辑

2007年6月8日
最近就遇到一个问题: 因为要在一个jpanel里面显示一幅图片,但是图片的实际大小,我们知道是不相同的.当然有一种方式可以解决完全显示的问题.那就是利用画图函数强制指定区域大小.
但是,明显,当我们需要实际显示图片大小时,上述方法就不适用了.
JPanel是一个比较特殊的组件,当我们把他添加到一个container里面后,它会自动调整显示大小,以配合container的大小,所以如果图片大大小超过container的大小,那么在jpanel中显示的始终只是可见的那部分,而不会是像预测的那样出现滚动条..
因此,解决问题的关键就到了,如何改变jpanel的大小.这里要指出,setBounds等函数是徒劳的.
下面给出一个完整片段:
JScrollPane jp=new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jp.setViewportView(iPanel);
以上两句是创建一个滚动窗口,并把一个panel加入其中并始终显示横竖滚动条.
下一步,就是调整panel的大小,以使滚动条真正的能工作起来.
iPanel.setPreferredSize(new Dimension(3000,2000));
iPanel.revalidate();
最好每次重绘之前,预先设置一下ipanel大小,然后调用revalidate更新.
这样,就容易的实现了滚动屏.对于其他的组件,是不需要上面那些步骤的,原因就是上面提过的那个jpanel会自适应的属性.
posted @ 2007-06-08 16:24 空空色色 阅读(521) 评论(0)
编辑

2007年4月24日
摘要: BMP是bitmap的缩写形式,bitmap顾名思义,就是位图也即Windows位图。它一般由4部分组成:文件头信息块、图像描述信息块、颜色表(在真彩色模式无颜色表)和图像数据区组成。在系统中以BMP为扩展名保存。 打开Windows的画图程序,在保存图像时,可以看到三个选项:2色位图(黑白)、16色位图、256色位图和24位位图。这是最普通的生成位图的工具,在这里讲解的BMP位图形式,主要就是...
阅读全文
posted @ 2007-04-24 15:02 空空色色 阅读(759) 评论(0)
编辑
posted @ 2007-04-24 14:54 空空色色 阅读(1467) 评论(2)
编辑

2007年4月19日
posted @ 2007-04-19 23:26 空空色色 阅读(2551) 评论(7)
编辑