/*
凑合了两份代码,就成了这个程序
是用来扫描MAC地址的
因为是凑合的,姑不敢称原创
编译环境:Borland C++ ---bcc32.exe -edemo scanmac.cpp
系统环境:XP_SP2
by asm http://www.asm32.cn/
*/
#include <windows.h>
#include <iphlpapi.h>
#include <winsock.h>
#include <winsock2.h>
#include <stdio.h>
#pragma comment (lib,"ws2_32.lib")
#pragma comment (lib,"Iphlpapi.lib")
int show(){
printf("********************************************************/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("********************************************************/r/n/r/n");
return 0;
}
int show();
int main(int argc,char *argv[])
{
show();
if (argc!=3)
{
printf("Usage: %s host netmask/r/n",argv[0]);
printf("Example: %s 192.168.0.1 255.255.255.0/r/n",argv[0]);
exit(0);
}
unsigned int uHostByte; /* 主机位 */
int i, uHostNum;
int numberOfHost = 1;
struct hostent *remoteHostent;
/* 两个临时变量 */
char TempIpAddr[4 * 4];
/* 由IP地址得到主机位 */
uHostByte = htonl(inet_addr(argv[1])) & 0xffffff00;
/*
由子网掩码得到网段内的主机数量
子网主机个数 = ~ MASK - 1
*/
uHostNum = ~ htonl(inet_addr(argv[2])) - 1;
printf(
"[+] Enum for adresses from %d.%d.%d.1-%d/n/n",
(uHostByte & 0xff000000) >> 0x18,
(uHostByte & 0x00ff0000) >> 0x10,
(uHostByte & 0x0000ff00) >> 0x08,
uHostNum
);
/*
开始进行多线程ARP扫描,创建uHostNum个线程扫描
Scan Range: 1 ~ uHostNum
*/
for (i = 0, uHostByte ++; i < uHostNum; i ++, uHostByte ++)
{
/* 构造IP地址 */
memset(TempIpAddr, 0, strlen(TempIpAddr));
sprintf(TempIpAddr, "%d.%d.%d.%d",
(uHostByte & 0xff000000) >> 0x18,
(uHostByte & 0x00ff0000) >> 0x10,
(uHostByte & 0x0000ff00) >> 0x08,
(uHostByte & 0x000000ff));
// printf("%s/n", TempIpAddr);
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData); //初始化WSAStartup
if(iRet != 0)
{
printf("WSAStartup Error:%d/n", GetLastError());
exit(0);
}
int nRemoteAddr = inet_addr(TempIpAddr); //转换IP为MAC格式
remoteHostent = (struct hostent*)malloc(sizeof(struct hostent )); //给hostent分配一块内存
struct in_addr sa; //in_addr结构
for(int i = 0; i < numberOfHost; i ++)
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf("/nIpAddress : %s/n", inet_ntoa(sa)); //获取主机名
remoteHostent = gethostbyaddr((char*)&nRemoteAddr,4, AF_INET); //从IP地址获取主机信息
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, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen); //发送ARP数据包
if(iRet == NO_ERROR)
{
printf("MacAddress: ");
for(int i =0; i<6; i++)
{
printf("%.2x", macAddress[i]); //MAC格式"XX"
if(i<5)printf("-"); //"XX-"
}
printf("/n");
}
else
printf("SendARP Error:%d/n", GetLastError());
nRemoteAddr = htonl(ntohl(nRemoteAddr)+ 1);
}
Sleep(2); /* 等待参数传递完毕,再重新赋值 */
}
/* 等待线程返回,退出函数 */
return i;
}
凑合了两份代码,就成了这个程序
是用来扫描MAC地址的
因为是凑合的,姑不敢称原创
编译环境:Borland C++ ---bcc32.exe -edemo scanmac.cpp
系统环境:XP_SP2
by asm http://www.asm32.cn/
*/
#include <windows.h>
#include <iphlpapi.h>
#include <winsock.h>
#include <winsock2.h>
#include <stdio.h>
#pragma comment (lib,"ws2_32.lib")
#pragma comment (lib,"Iphlpapi.lib")
int show(){
printf("********************************************************/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("Neokee是王八,ring04h是乌龟/n");
printf("********************************************************/r/n/r/n");
return 0;
}
int show();
int main(int argc,char *argv[])
{
show();
if (argc!=3)
{
printf("Usage: %s host netmask/r/n",argv[0]);
printf("Example: %s 192.168.0.1 255.255.255.0/r/n",argv[0]);
exit(0);
}
unsigned int uHostByte; /* 主机位 */
int i, uHostNum;
int numberOfHost = 1;
struct hostent *remoteHostent;
/* 两个临时变量 */
char TempIpAddr[4 * 4];
/* 由IP地址得到主机位 */
uHostByte = htonl(inet_addr(argv[1])) & 0xffffff00;
/*
由子网掩码得到网段内的主机数量
子网主机个数 = ~ MASK - 1
*/
uHostNum = ~ htonl(inet_addr(argv[2])) - 1;
printf(
"[+] Enum for adresses from %d.%d.%d.1-%d/n/n",
(uHostByte & 0xff000000) >> 0x18,
(uHostByte & 0x00ff0000) >> 0x10,
(uHostByte & 0x0000ff00) >> 0x08,
uHostNum
);
/*
开始进行多线程ARP扫描,创建uHostNum个线程扫描
Scan Range: 1 ~ uHostNum
*/
for (i = 0, uHostByte ++; i < uHostNum; i ++, uHostByte ++)
{
/* 构造IP地址 */
memset(TempIpAddr, 0, strlen(TempIpAddr));
sprintf(TempIpAddr, "%d.%d.%d.%d",
(uHostByte & 0xff000000) >> 0x18,
(uHostByte & 0x00ff0000) >> 0x10,
(uHostByte & 0x0000ff00) >> 0x08,
(uHostByte & 0x000000ff));
// printf("%s/n", TempIpAddr);
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData); //初始化WSAStartup
if(iRet != 0)
{
printf("WSAStartup Error:%d/n", GetLastError());
exit(0);
}
int nRemoteAddr = inet_addr(TempIpAddr); //转换IP为MAC格式
remoteHostent = (struct hostent*)malloc(sizeof(struct hostent )); //给hostent分配一块内存
struct in_addr sa; //in_addr结构
for(int i = 0; i < numberOfHost; i ++)
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf("/nIpAddress : %s/n", inet_ntoa(sa)); //获取主机名
remoteHostent = gethostbyaddr((char*)&nRemoteAddr,4, AF_INET); //从IP地址获取主机信息
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, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen); //发送ARP数据包
if(iRet == NO_ERROR)
{
printf("MacAddress: ");
for(int i =0; i<6; i++)
{
printf("%.2x", macAddress[i]); //MAC格式"XX"
if(i<5)printf("-"); //"XX-"
}
printf("/n");
}
else
printf("SendARP Error:%d/n", GetLastError());
nRemoteAddr = htonl(ntohl(nRemoteAddr)+ 1);
}
Sleep(2); /* 等待参数传递完毕,再重新赋值 */
}
/* 等待线程返回,退出函数 */
return i;
}