易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux获取本机IP、MAC示例程序

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstring>
using namespace std;
void peek_interfaces(int fd);
void print_hw_addr(int fd, const char* if_name);
int main() {
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if(-1 == fd) {
perror("Failed create socket.");
return -1;
}
peek_interfaces(fd);
close(fd);
return 0;
}
void peek_interfaces(int fd) {
ifreq ifs[16] = {0};
ifconf conf = {sizeof(ifs)};
conf.ifc_req = ifs;
if(-1 == ioctl(fd, SIOCGIFCONF, &conf)) {
perror("Failed IOCTL SIOCGIFCONF.");
return;
}
if(conf.ifc_len >= sizeof(ifs)) {
perror("Buffer too small for IOCTL SIOCGIFCONF.");
return;
}

int num = conf.ifc_len / sizeof(ifreq);
cout << num << " interface entry retrieved." << endl;
for(int i = 0; i < num; ++i) {
cout << "[ " << ifs[i].ifr_name << " ]" << endl;
sockaddr_in* sai = (sockaddr_in*)&ifs[i].ifr_addr;
cout << "Addr: " << inet_ntoa(sai->sin_addr) << endl;
print_hw_addr(fd, ifs[i].ifr_name);
cout << endl;
}
}
void print_hw_addr(int fd, const char* if_name) {
ifreq req = {0};
strcpy(req.ifr_name, if_name);
if(-1 == ioctl(fd, SIOCGIFFLAGS, &req)) {
perror("Failed IOCTL SIOCGIFFLAGS.");
return;
}
if(req.ifr_flags & IFF_LOOPBACK) {
cout << "Is LOOPBACK." << endl;
return;
}
if(-1 == ioctl(fd, SIOCGIFHWADDR, &req)) {
perror("Failed IOCTL SIOCGIFHWADDR.");
return;
}
unsigned char* puc = (unsigned char*)req.ifr_hwaddr.sa_data;
printf("HW addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
puc[0], puc[1], puc[2], puc[3], puc[4], puc[5]);
}


相关文档:

Linux 下配置 ITK

在 linux 下配置 ITK
1. 下载 CMake:http://www.cmake.org/cmake/resources/software.html
    为方便安装,这里下载二进制文件,选择下载: cmake-2.6.4-Linux-i386.sh
2. 安装 CMake, 到  cmake-2.6.4-Linux-i386.sh 存放的目录,输入,可用 TAB 键方便补齐命令
    #./ cmake-2. ......

ubuntu linux 下面mount fedora 逻辑卷 lvm的方法

今天fedora挂了,为了备份数据用ubuntu的livecd来进行数据备份,从网上看到了一篇帖子,
http://www.linux-sxs.org/storage/fedora2ubuntu.html
解决了问题
内容如下:
Boot Ubuntu.
Install lvm2:
$ sudo apt-get install lvm2
Load the necessary module(s):
$ sudo modprobe dm-mod
Scan your system for LVM v ......

Linux创建一定大小文件命令

dd命令
把指定的输入文件拷贝到指定的输出文件中,并且在拷贝的过程中可以进行格式转换。语法:
CODE:[Copy to clipboard]dd 〔选项〕
QUOTE:
if =输入文件(或设备名称)。
of =输出文件(或设备名称)。
ibs = bytes 一次读取bytes字节,即读入缓冲区的字节数。
skip = blocks 跳过读入缓冲区开头的ibs*blo ......

减少Linux下Squid服务器的TIME_WAIT套接字数量

Linux下高并发的Squid服务器,TCP TIME_WAIT套接字数量经常达到两、三万,服务器很容易被拖死。通过修改Linux内核参数,可以减少Squid服务器的TIME_WAIT套接字数量。
  
vi /etc/sysctl.conf
  增加以下几行:
引用
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookie ......

Linux——linux命令集


NO
分类
PS1
命令名
用法及参数
功能注解
1
显示目录信息
#
ls
ls -a
列出当前目录下的所有文件,包括以.头的隐含文件
#
ls
ls -l或ll
列出当前目录下文件的详细信息
#
ls
ls -a
显示所有文件,包含隐藏。
#
ls
ls -al
显示所有文件的详细信息。
2
查看路径
#
pwd
pwd
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号