Linux下利用ppp-on指令碼進行GPRS撥接

來源:互聯網
上載者:User
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#存放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函數,在子進程中執行指令碼,而在父進程中執行自己的程式即可

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.