-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 自动识别网卡登录
- Loading branch information
leetking
authored and
leetking
committed
Sep 3, 2016
1 parent
cd195a2
commit 372010a
Showing
7 changed files
with
213 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
drcom.exe | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
# 这是注释 | ||
# 使用方法: | ||
# 把这个文件里的信息填写成你自己的,然后重命名为drcomrc | ||
ethif = "eth0" #网络接口 | ||
uname = "201413640731" #用户名 | ||
pwd = "pwd" #密码 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include <pcap.h> | ||
#include "wrap_eapol.h" | ||
#include "type.h" | ||
#include "eapol.h" | ||
|
||
|
||
#define IFDESCSIZ (126) | ||
typedef struct { | ||
char name[IFNAMSIZ]; /* linux下是eth0, windows采用的是注册表类似的(\Device\NPF_{xxxx-xxx-xx-xx-xxx}) */ | ||
#ifdef WINDOWS | ||
char desc[IFDESCSIZ]; /* windows下描述(AMD PCNET Family PCI Ethernet Adapter) */ | ||
#endif | ||
}iflist_t; | ||
|
||
static int is_filter(char const *ifname) | ||
{ | ||
/* 过滤掉无线,虚拟机接口等 */ | ||
char const *filter[] = { | ||
/* windows */ | ||
"Wireless", "Microsoft", | ||
"Virtual", | ||
/* linux */ | ||
"lo", "wlan", "vboxnet", | ||
}; | ||
for (int i = 0; i < ARRAY_SIZE(filter); ++i) { | ||
if (strstr(ifname, filter[i])) | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
/* | ||
* 获取所有网络接口 | ||
* ifnames 实际获取的接口 | ||
* cnt 两个作用,1:传入表示ifnames最多可以存储的接口个数 | ||
* 2:返回表示实际获取了的接口个数 | ||
* 返回接口个数在cnt里 | ||
* @return: >=0 成功,实际获取的接口个数 | ||
* -1 获取失败 | ||
* -2 cnt过小 | ||
*/ | ||
static int getall_ifs(iflist_t *ifs, int *cnt) | ||
{ | ||
int i = 0; | ||
if (!ifs || *cnt <= 0) return -2; | ||
#ifdef LINUX /* linux (unix osx?) */ | ||
#define _PATH_PROCNET_DEV "/proc/net/dev" | ||
#define BUFF_LINE_MAX (1024) | ||
char buff[BUFF_LINE_MAX]; | ||
FILE *fd = fopen(_PATH_PROCNET_DEV, "r"); | ||
char const *filter[] = { | ||
"lo", "docker", | ||
"wlan", "vboxnet", | ||
}; | ||
char *name; | ||
if (NULL == fd) { | ||
perror("fopen"); | ||
return -1; | ||
} | ||
/* _PATH_PROCNET_DEV文件格式如下,...表示后面我们不关心 | ||
* Inter-| Receive ... | ||
* face |bytes packets ... | ||
* eth0: 147125283 119599 ... | ||
* wlan0: 229230 2635 ... | ||
* lo: 10285509 38254 ... | ||
*/ | ||
/* 略过开始两行 */ | ||
fgets(buff, BUFF_LINE_MAX, fd); | ||
fgets(buff, BUFF_LINE_MAX, fd); | ||
while (0 < fgets(buff, BUFF_LINE_MAX, fd)) { | ||
name = get_ifname_from_buff(buff); | ||
_D("%s\n", name); | ||
/* 过滤无关网络接口 */ | ||
if (is_filter(name)) { | ||
_D("filtered %s.\n", name); | ||
continue; | ||
} | ||
strncpy(ifs[i].name, name, IFNAMSIZ); | ||
_D("ifs[%d].name: %s\n", i, ifs[i].name); | ||
++i; | ||
if (i >= *cnt) { | ||
fclose(fd); | ||
return -2; | ||
} | ||
} | ||
fclose(fd); | ||
#elif defined(WINDOWS) | ||
pcap_if_t *alldevs; | ||
char errbuf[PCAP_ERRBUF_SIZE]; | ||
if (-1 == pcap_findalldevs(&alldevs, errbuf)) { | ||
_M("Get interfaces handler error: %s\n", errbuf); | ||
return -1; | ||
} | ||
for (pcap_if_t *d = alldevs; d; d = d->next) { | ||
if (is_filter(d->description)) { | ||
_D("filtered %s.\n", d->description); | ||
continue; | ||
} | ||
if (i >= *cnt) return -2; | ||
strncpy(ifs[i].name, d->name, IFNAMSIZ); | ||
strncpy(ifs[i].desc, d->description, IFDESCSIZ); | ||
++i; | ||
} | ||
pcap_freealldevs(alldevs); | ||
#endif | ||
*cnt = i; | ||
return i; | ||
} | ||
|
||
|
||
extern int try_smart_login(char const *uname, char const *pwd, | ||
int (*sucess_handle)(void const*), void const *args) | ||
{ | ||
iflist_t ifs[IFS_MAX]; | ||
int ifs_max = IFS_MAX; | ||
if (0 >= getall_ifs(ifs, &ifs_max)) return -3; | ||
for (int i = 0; i < ifs_max; ++i) { | ||
_M("%d. try interface (%s) to login\n", i, | ||
#ifdef LINUX | ||
ifs[i].name | ||
#elif defined(WINDOWS) | ||
ifs[i].desc | ||
#endif | ||
); | ||
setifname(ifs[i].name); | ||
int statu; | ||
switch (statu = eaplogin(uname, pwd, NULL, NULL)) { | ||
default: | ||
break; | ||
case 0: | ||
case 1: | ||
case 2: | ||
return statu; | ||
} | ||
} | ||
return -3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef _WRAP_EAPOL_H | ||
#define _WRAP_EAPOL_H | ||
/* | ||
* 对eapol登录的一个包裹,实现自己选择网卡登录 | ||
*/ | ||
|
||
/* | ||
* 自动选择网卡登录 | ||
*/ | ||
extern int try_smart_login(char const *uname, char const *pwd, | ||
int (*sucess_handle)(void const*), void const *args); | ||
|
||
|
||
#endif |