Chinaunix首页 | 论坛 | 博客
  • 博客访问: 478573
  • 博文数量: 285
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 629
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-14 17:53
个人简介

相信自己,快乐每一天

文章分类

全部博文(285)

分类:

2013-10-30 15:44:27

Linux下拨号采用的是PPP协议,这与windows是一致的.
只是windows下采用拨号程序对协议用图形化界面加以封装,因此我们在拨号时不易察觉.
而在Linux下,采利用的是pppd程序,因此较windows而言能理解的更清楚.
Linux下的GUI拨号程序是KPPP,其实也是将pppd加以封装而已.

在Linux下拨号采用的脚本为ppp-on,ppp-on-dialer,ppp-off
在默认安装的RH9下可以在/usr/share/doc/ppp/script下找到这三个脚本

这三个脚本原本是用来为普通的调制解调器作拨号脚本的,
我们可以利用这三个脚本做一定的修改,即可实现ppp拨号GPRS上网.

拨号原理为:
初始化模块,主要是设定APN:CMNET
at+cgdcont=1,ip,cmnet
然后利用chat程序拨号*99***1#
待拨号连接成功后,由pppd将建立通信链路即可.

脚本改动如下:
在ppp-on里改了电话号码为*99***1#
将账号与密码清除,
改了DIALER_SCRIPT的路径
把下面的设备改成/dev/ttyS0,速率改为19200
将crtscts参数去掉,
  
在ppp-on-dialer里把帐号密码去掉

改动后的脚本如下:
#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command.  However, it is simple.
#
# These are the parameters. Change as needed.
TELEPHONE=*99***1#    # The telephone number for the connection
ACCOUNT=        # The account name for logon (as in 'George Burns')
PASSWORD=        # The password for this account (and 'Gracie Allen')
LOCAL_IP=0.0.0.0    # Local IP address if known. Dynamic = 0.0.0.0
REMOTE_IP=0.0.0.0    # Remote IP address if desired. Normally 0.0.0.0
NETMASK=255.255.255.0    # The proper netmask if needed
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE ACCOUNT PASSWORD
#
# This is the location of the script which dials the phone and logs
# in.  Please use the absolute file name as the $PATH variable is not
# used on the connect option.  (To do so on a 'root' account would be
# a security hole so don't ask.)
#
DIALER_SCRIPT=/home/testBoot/ppp/ppp-on-dialer
#
# Initiate the connection
#
# I put most of the common options on this command. Please, don't
# forget the 'lock' option or some programs such as mgetty will not
# work. The asyncmap and escape will permit the PPP link to work with
# a telnet or rlogin connection. You are welcome to make any changes
# as desired. Don't use the 'defaultroute' option if you currently
# have a default route to an ethernet gateway.
#
exec /usr/sbin/pppd debug lock nocrtscts modem /dev/ttyS0 19200 \
    asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \
    noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT


在改动完成后,执行脚本ppp-on
./ppp-on
即可拨号上网

如要自己写程序来执行此脚本的话,则利用EXEC函数即可,至于EXEC的具体用法,可参阅C函数的说明书
有一点要提醒的是,在利用EXEC的时候,原进程会湮灭,而只有所执行程序的进行在运行,因此,如果想保留原进程,我采用的方法是利用fork函数,在子进程中执行脚本,而在父进程中执行自己的程序即可
阅读(1076) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~