LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1401|回复: 2

linux下编辑c语言的问题???我主要想得到内部网中的其他电脑的机器名!

[复制链接]
发表于 2002-11-14 09:02:49 | 显示全部楼层 |阅读模式
我主要想得到内部网中的其他电脑的机器名!

我在网上发现一个获取远程机器名与Mac地址的程序,

可是我在linux上运行gcc -o test2 -lm test.c
报错:
test2.c:3:23:Winsock2.h: No such file or directory
test2.c:4:23:iphlpapi.h: No such file or directory

test2.c 程序如下:
#include "stdio.h"
#include "stdlib.h"
#include "Winsock2.h"
#include "iphlpapi.h"

#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )

void main( int argc, char ** argv )
{
//处理命令行参数
if ( argc != 2 )
{
 printf( "RmtHost v0.1 - Get remote HostName /MacAddress\n" );
 printf( "by ShotgunLabs ( Shotgun@xici.net )\n\n" );
 printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n");
 printf( "Example:\n\tRmtHost.exe 192.168.0.3\n\n");
 exit( 0 );
}

printf( "\nIpAddress : %s\n", argv[1] );
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
 printf( "WSAStartup Error:%d\n", GetLastError() );
 exit( 0 );
}
//获取远程机器名
hostent * remoteHostent = (hostent*)malloc( sizeof( hostent ));
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,sizeof( in_addr ), AF_INET );
if ( remoteHostent )
 printf( "HostName : %s\n",remoteHostent->h_name );
else
 printf( "gethostbyaddr Error:%d\n", GetLastError());

//发送ARP查询包获得远程MAC地址
unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet = SendARP( nRemoteAddr, NULL, (PULONG)&macAddress,&macAddLen );
if ( iRet == NO_ERROR )
{
 printf( "MacAddress: " );
 for( int i =0; i<6; i++ )
 {
  printf( "%.2x", macAddress );
  if ( i<5 ) printf( "-" );
 }
}
else
 printf( "SendARP Error:%d\n", GetLastError() );
printf( "\n" );
}
发表于 2002-11-14 09:39:29 | 显示全部楼层
在/usr/include/sys下没有这个头文件,用visual c++编译试一下
 楼主| 发表于 2002-11-14 10:41:24 | 显示全部楼层

我主要想在linux下得到内部网中的其他电脑的机器名!帮忙改改!

谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表