宿舍上网插件以及用法

在linux下用宿舍的宽带上网相信是大家一致困扰的问题,最近我在网上找到的教程很是详细。因此贴出来与大家分享。

1,在VMware(虚拟机)上安装Linux,只要物理机上连上网 ,虚拟机就可以上网了 不用做任何配置!
2,如果你装的是双系统的话,那就更简单了!上网配置如下:
步骤一:使用命令:sudo pppoeconf 就会出现配置用户名和密码的界面:
 首先出现的是ueser name 你把它删了 输入你的用户名(就是你办的网号的用户名)
 下一步输入你的密码(同样道理是你的宽带密码),然后一直next下去就可以了。
 做完这,你就离成功不远了
步骤二:你下载一个文件(drcom.c)把它放在桌面
 再打开终端:输入:ls 就会出现当前目录下的文件,然后再输入:cd 桌面 ,这就到了你的“桌面这个目录下”,
再次输入命令:ls 列表你的文件,你就会看到drcom.c这个文件,再一次输入命令:gcc drcom.c -o drcom 执行完这个命令以后,
在你的桌面上就会看到一个可执行文件。如果到这一步,恭喜你,你已经完了99%
步骤三:
 打开你的系统(不好意思忘了)就是在火狐浏览的左边,找到启动管理器 >添加>l浏览>桌面>drcom>关闭
OK!你已经成功了!完成以上配置后,你每一次打开linux时,不用手动联网 ,其实它已经自动连上网了!不用像win7/xp一
样还有手动连接。!麻烦!

附 drcom.c源文件
//用记事本保存为Drcom.c,就是把后缀名TXT改为.c
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>

typedef struct _code2 {
char sign;
char type;
short len;
int id;
int code0;
int code1;
}code2;

typedef struct _code3 {
char sign;
char type;
short len;
int id;
int unk0;
int code1;
int unk1;
int code0;
int check;
int unk2;
char mac[6];
char dhcp;
char devtype;
int ipaddr;
int netmask;
char padding[48];
}code3;

int waitdata(int hsocket, int time)
{
fd_set fds;
struct timeval tv;

FD_ZERO(&fds);
FD_SET(hsocket,&fds);
tv.tv_usec = time;
tv.tv_sec = 0;
return select(hsocket+1,&fds,NULL,NULL,&tv);
}

main (int argc, char* argv[])
{
struct in_addr ip,netmask,ptp;
char mac[6];
int hsocket;
struct ifreq ifr;
struct sockaddr_in sin;
struct sockaddr *sa = (struct sockaddr *) &sin;
int fromlen;
struct sockaddr_in *sin_ptr;
u_char *ptr;
u_long *ptr_long;
int n;
int check;
char c1[] = {7,1,8,0,1,0,0,0};
code2 c2;
code3 c3;
char c4[512];
int sendlen, recvlen;
int errorcount,workwell,noticed=0;

printf("nFree Dr.COM for Linux v0.3n mengxp works,2009 @ xiyoun http://www.deadc0de.com/nn");

init:
if ((hsocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror( "socket error!");
return 0;
}

errorcount = 0;
strcpy(ifr.ifr_name, "ppp0");
if (ioctl(hsocket, SIOCGIFADDR, &ifr) < 0)
{
// perror("ioctl SIOCGIFADDR error");
errorcount++;
}
sin_ptr = (struct sockaddr_in *)&ifr.ifr_addr;
ip = sin_ptr->sin_addr;

if (ioctl(hsocket, SIOCGIFNETMASK, &ifr) < 0)
{
// perror("ioctl SIOCGIFNETMASK error");
errorcount++;
}
sin_ptr = (struct sockaddr_in *)&ifr.ifr_addr;
netmask = sin_ptr->sin_addr;

if (ioctl(hsocket, SIOCGIFDSTADDR, &ifr) < 0)
{
// perror("ioctl SIOCGIFDSTADDR error");
errorcount++;
}
sin_ptr = (struct sockaddr_in *)&ifr.ifr_addr;
ptp = sin_ptr->sin_addr;
memset(&mac,0,6);

if(errorcount)
{
close(hsocket);
if(!noticed)
printf("couldn't get ppp0 interface!nplease check your connection!nn");
noticed++;
sleep(3);
goto init;
}
else
noticed = 0;

printf("ppp0 interface:n");
printf(" IP: %sn", inet_ntoa(ip));
printf(" NetMask: %sn", inet_ntoa(netmask));
printf(" Server: %snn", inet_ntoa(ptp));

sin.sin_addr = ip;
sin.sin_port = htons(61440);
sin.sin_family = AF_INET;
if ((bind(hsocket,sa,sizeof(sin))) < 0)
{
printf( "can't bind udp port 61440!n");
return 0;
}

sin.sin_addr = ptp;
printf("Activating connection...n");

workwell = 0;
keepalive:
errorcount = 0;
while(1)
{
sendlen = sendto(hsocket,&c1,8,MSG_NOSIGNAL,sa,sizeof(sin));
if(sendlen < 0 || errorcount >= 5)
{
printf("socket error! reinit...n");
close(hsocket);
goto init;
}
if(waitdata(hsocket,1000*1000))
{
fromlen = sizeof(sin);
recvlen = recvfrom(hsocket,&c2,sizeof(c2),0,sa,&fromlen);
ip = sin.sin_addr;
break;
}
else
{
errorcount++;
printf("recv2 timed outn");
}
}

memset(&c3,0,96);
c3.sign = 7;
c3.len = 96;
c3.id = 3;
c3.code1 = c2.code1;
c3.unk1 = 0x2000200;
c3.code0 = c2.code0;
c3.check = 0x1312fc7;
c3.unk2 = 0x7e;
memcpy(&c3.mac,&mac,6);
c3.devtype = 0x17;
memcpy(&c3.ipaddr,&ip,4);
memcpy(&c3.netmask,&netmask,4);

ptr_long = (u_long *)&c3;
for(n=0,check=0;n<96/4;n++)
check ^= *(ptr_long + n);
c3.check = check * 0x12C4B7E;
c3.unk2 = 0;

ptr = (u_char *)&c3.mac;
for(n=0;n<64;n++)
*(ptr + n) = (*(ptr + n) >> 8 - (n & 7)) + (*(ptr + n) << (n & 7));

sendlen = sendto(hsocket,&c3,96,MSG_NOSIGNAL,sa,sizeof(sin));
if(sendlen < 0 || errorcount >= 5)
{
printf("socket error! reinit...n");
close(hsocket);
goto init;
}
if(waitdata(hsocket,1000*1000))
{
fromlen = sizeof(sin);
recvlen = recvfrom(hsocket,&c2,sizeof(c2),0,sa,&fromlen);
if(!workwell)
{
printf("Keeping connection active...n");
workwell++;
}
}
else
{
printf("recv4 timed outn");
sleep(1);
goto keepalive;
}

sleep(15);
goto keepalive;
return 0;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注