CN102426520A - 一种获取Linux系统网路设备信息的方法 - Google Patents

一种获取Linux系统网路设备信息的方法 Download PDF

Info

Publication number
CN102426520A
CN102426520A CN2011103216790A CN201110321679A CN102426520A CN 102426520 A CN102426520 A CN 102426520A CN 2011103216790 A CN2011103216790 A CN 2011103216790A CN 201110321679 A CN201110321679 A CN 201110321679A CN 102426520 A CN102426520 A CN 102426520A
Authority
CN
China
Prior art keywords
filename
file
pszdata
linux
configuration file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2011103216790A
Other languages
English (en)
Inventor
张世刚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inspur Electronic Information Industry Co Ltd
Original Assignee
Inspur Electronic Information Industry Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN2011103216790A priority Critical patent/CN102426520A/zh
Publication of CN102426520A publication Critical patent/CN102426520A/zh
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供一种获取Linux系统网路设备信息的方法,这些设备信息包括网卡类型、网卡物理地址、IP地址、子网掩码、网关等,用该方法编译成的动态链接库可以供Java通过rmi调用;该方法用C++语言来控制Linux命令的执行,从而获得Linux系统下网络设备的配置信息,本发明的方法可以用来支持一些设备监控软件,避免重复的输入命令获取需要的信息,从而能够提高服务器的管理效率。

Description

一种获取Linux系统网路设备信息的方法
  
技术领域
本发明涉及一种计算机应用技术领域, 具体地说是一种获取Linux系统网路设备信息的方法。 
背景技术
随着计算机集群规模的膨胀,传统的对服务器的管理方法越来越不适用,需要一套集群监控管理软件来对庞大的计算机集群进行管理,以提高管理的效率和降低管理成本。本发明,就是为集群监控管理软件提供支持的方法。 
  传统的方法是直接到服务器上,输入命令来获得所需要的网络设备信息;该方法是一种通过程序来获得网络设备配置信息的方法,可以用来支持一些设备监控软件,避免重复的输入命令获取需要的信息,从而能够提高服务器的管理效率。   
发明内容
本发明的目的是提供一种用基于Linux命令的程序获取网络设备信息的方法。 
本发明的目的是按以下方式实现的,步骤如下: 
1)用Linux命令获得Linux网络设备配置文件的文件名,保存到一个临时文件中;操作步骤如下:
char cmd[256]=”ls/etc/sysconfig/network-scripts/ifcfg-* | cut 
-d \"/\" -f 5 > ”;
char tempfile[256]=” /tmp/netInfolc-XXXXXX”;
mkstemp(tempfile) ;//创建临时文件
strcat(cmd, tempfile);//拼接字符串
system(cmd);//执行命令;
2)用C++代码创建一个关于临时文件的I/O流,获取网络设备的配置文件名;再控制Linux命令执行,到网络设备配置文件所在的目录下,创建一个关于配置文件的I/O流,用来获取网络设备的配置信息;操作步骤如下:
ifstream file(tempfile);//得到临时文件的I/O流
char  filename[256] = ” ”; //配置文件的名称
while( file.getline (filename, SIZELN ) ){  
strcat("/etc/sysconfig/network-scripts/", filename);
   ifstream netInfoFile( strInfo );  
   char pszData[512]=””;    //配置文件中的一行内容
   int SIZE=512;
   while ( netInfoFile.getline( pszData, SIZE ) )
    {
      Int  strlen = pszData.length();
       Int  position = pszData.find( "=", 0); 
 if (pszData.find( "TYPE=", 0) != string::npos )
       {
           strcpy( info2, (pszData.substr( position+1, 
                  strlen-position ) ).c_str() );
          continue;
       }//end of if
       . 得到需要的值
    }
};
3)将得到的这些数据保存到集合vector<vector<string> >中。 
具体实施方式
对本发明的方法作以下详细地说明。 
发明提供一种用基于Linux命令的C++程序获取网路设备信 
息的方法,这些设备信息包括网卡类型、网卡物理地址、IP地址、子网掩码、网关等,用该方法编译成的动态链接库可以供Java通过rmi调用。该方法用C++来控制Linux命令的执行,首先用Linux命令获得所有网络设备配置文件的名称并保存到一个临时文件中;
然后创建一个配置文件的I/O流获得配置文件中的网络设备信息。
实施例
该方法通过以下步骤实现: 
1)用Linux命令获得Linux网络设备配置文件的文件名,保存到一个临时文件中。
char cmd[256]=”ls/etc/sysconfig/network-scripts/ifcfg-* | cut 
-d \"/\" -f 5 > ”;
char tempfile[256]=” /tmp/netInfolc-XXXXXX”;
mkstemp(tempfile) ;//创建临时文件
strcat(cmd, tempfile);//拼接字符串
system(cmd);//执行命令
2)用C++代码执行Linux命令到配置文件的目录下,根据获得 的配置文件名创建I/O流,获得配置文件里的网络设备信息。
ifstream file(tempfile);//得到临时文件的I/O流 
char  filename[256] = ” ”; //配置文件的名称
while( file.getline (filename, SIZELN ) ){  
strcat("/etc/sysconfig/network-scripts/", filename);
   ifstream netInfoFile( strInfo );  
   char pszData[512]=””;    //配置文件中的一行内容
   int SIZE=512;
   while ( netInfoFile.getline( pszData, SIZE ) )
    {
      Int  strlen = pszData.length();
       Int  position = pszData.find( "=", 0); 
 if (pszData.find( "TYPE=", 0) != string::npos )
       {
           strcpy( info2, (pszData.substr( position+1, 
                  strlen-position ) ).c_str() );
         continue;
       }//end of if
       . 得到需要的值
    }
}
3)将得到的这些数据保存到集合vector<vector<string> >中。

Claims (2)

1.一种获取Linux系统网路设备信息的方法,其特征在于步骤包括:
1)用Linux命令获得Linux网络设备配置文件的文件名,保存到一个临时文件中;操作步骤如下:
char cmd[256]=”ls/etc/sysconfig/network-scripts/ifcfg-* | cut 
-d \"/\" -f 5 > ”;
char tempfile[256]=” /tmp/netInfolc-XXXXXX”;
mkstemp(tempfile) ;//创建临时文件
strcat(cmd, tempfile);//拼接字符串
system(cmd);//执行命令;
2)用C++代码创建一个关于临时文件的I/O流,获取网络设备的配置文件名;再控制Linux命令执行,到网络设备配置文件所在的目录下,创建一个关于配置文件的I/O流,用来获取网络设备的配置信息;操作步骤如下:
ifstream file(tempfile);//得到临时文件的I/O流
char  filename[256] = ” ”; //配置文件的名称
while( file.getline (filename, SIZELN ) ){  
strcat("/etc/sysconfig/network-scripts/", filename);
   ifstream netInfoFile( strInfo );  
   char pszData[512]=””;    //配置文件中的一行内容
   int SIZE=512;
   while ( netInfoFile.getline( pszData, SIZE ) )
      {
      Int  strlen = pszData.length();
         Int  position = pszData.find( "=", 0); 
 if (pszData.find( "TYPE=", 0) != string::npos )
           {
              strcpy( info2, (pszData.substr( position+1, 
                  strlen-position ) ).c_str() );
              continue;
           }//end of if
       .
.
       . 得到需要的值
       .
       .     
    }
}。
2.根据权利要求1所述的方法,其特征在于,用C++代码执行Linux命令,首先到配置文件所在的目录下获取所有关于网络设备配置文件的文件名,并将获得的文件名保存起来供接下来的流程用。
CN2011103216790A 2011-10-21 2011-10-21 一种获取Linux系统网路设备信息的方法 Pending CN102426520A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2011103216790A CN102426520A (zh) 2011-10-21 2011-10-21 一种获取Linux系统网路设备信息的方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2011103216790A CN102426520A (zh) 2011-10-21 2011-10-21 一种获取Linux系统网路设备信息的方法

Publications (1)

Publication Number Publication Date
CN102426520A true CN102426520A (zh) 2012-04-25

Family

ID=45960510

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2011103216790A Pending CN102426520A (zh) 2011-10-21 2011-10-21 一种获取Linux系统网路设备信息的方法

Country Status (1)

Country Link
CN (1) CN102426520A (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060173913A1 (en) * 2005-01-31 2006-08-03 Canon Kabushiki Kaisha Image Processing Apparatus and Image Processing Method
CN101174240A (zh) * 2006-11-03 2008-05-07 凌阳科技股份有限公司 一种软件测试管理方法及其系统
CN101794313A (zh) * 2010-03-10 2010-08-04 中国农业大学 嵌入式系统的文件搜索装置

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060173913A1 (en) * 2005-01-31 2006-08-03 Canon Kabushiki Kaisha Image Processing Apparatus and Image Processing Method
CN101174240A (zh) * 2006-11-03 2008-05-07 凌阳科技股份有限公司 一种软件测试管理方法及其系统
CN101794313A (zh) * 2010-03-10 2010-08-04 中国农业大学 嵌入式系统的文件搜索装置

Similar Documents

Publication Publication Date Title
CN102752137B (zh) 主动设置虚拟机网络参数的装置和方法
CN104636189B (zh) 基于Xen的虚拟机部署系统及方法
CN103412768A (zh) 一种基于脚本程序自动化部署Zookeeper集群的方法
WO2012054192A3 (en) Web service patterns for globally distributed service fabric
CN107707687A (zh) 一种虚拟机ip地址配置的方法和装置
CN102567074A (zh) 一种面向虚拟机的usb设备重定向方法
CN101894059B (zh) 一种运行状态的检测方法及系统
CN108563455A (zh) 一种k-ux操作系统上中间件部署方法、系统及设备
CN103686147A (zh) 一种克隆视频监控仿真终端的测试方法及装置
CN104158905B (zh) web容器的创建方法
CN102082797A (zh) 一种对数据流进行协议解析处理的方法及装置
CN105607606B (zh) 一种基于双主板架构的数据采集装置及方法
CN105407150A (zh) 应用程序远程控制方法
CN102426520A (zh) 一种获取Linux系统网路设备信息的方法
JP2009265718A (ja) ネットワーク管理情報の差分データのみを送信するネットワーク装置、サーバ、プログラム及び方法
CN110493036A (zh) 一种网关的管控方法
CN111796985B (zh) 一种数据库运行日志上传方法
KR101075837B1 (ko) 제어 시스템간 통신 장치
JP2010134574A (ja) ビジネスプロセス定義変更方法及びその実施システムとプログラム
JP2008243070A (ja) 環境移行サーバ装置、端末装置、環境移行方法及び環境移行プログラム
CN104699787B (zh) 一种用户活动状态记录的更新方法及装置
CN110336852B (zh) 一种基于分身手机的自动抢单、执行工单的方法
CN103092736B (zh) 服务程序监控的方法及装置
CN104639574A (zh) 数据处理系统及装置
CN105871678B (zh) 远程管理私有网络内终端设备的方法

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C02 Deemed withdrawal of patent application after publication (patent law 2001)
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20120425