Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using 10.04 Server.

I have a 3G wireless card, use the switch program which i get from the manufacturer, i can change the 3G card from USB storage mode to 3G modem mode, then following devices are created in /dev :ttyUSB0,ttyUSB1,ttyUSB2.

But I don't know which device to should choose to use 3G, so i have to run wvdialconfig to scan all the possible port and find the proper one. Is there a way to automatically detect the 3G port without using wvdialconfig to scan all the port every time?

share|improve this question
Answered in:… – Stuart Jan 4 '12 at 17:57
@Stuart I know how to use 3G modem but i just wanna find a automatically way to establish a connection using 3G modem. I mean after switching the 3G modem from a usb storage device to a modem, you have to use wvdialconf EVERY TIME because there are THREE ttyUSB devices(ttyUSB0,ttyUSB1,ttyUSB2) in /dev after switching, after using wvdialconf, this time i may use ttyUSB0 to dial, next time may be ttyUSB1. It's uncertain that i have to use wvdialconf every time after switch. Do you get it? – HexForFun Jan 4 '12 at 18:27
use usb_modeswitch: after installation it will automatically convert your modem from usb to modem mode. Goto Network connection->mobileBroadband, edit your connection and check for "connect automatically". So when you will start ubuntu usb_modeswitch switch your modem and network-manager automatically connect you with internet. – shantanu Jan 4 '12 at 19:17
@shantanu Do you mean use network-manager applet to set connect automatically to achieve that? i think it should be work,but my working environment is a pure command line interface and no graphic desktop installed, so i choose wvdial for connecting. Is there a way in CLI? – HexForFun Jan 4 '12 at 19:28
can you just post the commands what you give in command line after load your modem in /dev/ttyUSB*. (wvconfig) – shantanu Jan 4 '12 at 19:40

If you connect with network manager, it will work out which one to use. (You can drive it from the command line with nmcli)

share|improve this answer
There is not such command nmcli. – HexForFun Jan 6 '12 at 14:40
@HexForFun: It only appeared in maverick – tumbleweed Jan 6 '12 at 15:05
I use 10.04(server version). Can you give a common way to do that? – HexForFun Jan 6 '12 at 15:15
Sorry, there were no command line clients for NM in 10.04. You can drive it by the DBus API, but that's harder. – tumbleweed Jan 6 '12 at 17:30
Can you give me an example?? – HexForFun Jan 7 '12 at 1:06

Suppose your wvconf file is like this:

[Dialer Defaults]
Modem = /dev/ttyUSB1
Baud = 960800                      //Connection speed
Init = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = USB Modem
Phone = #777                       // Dialling number
Username = jimstech                // username
Password = jimstech                // password
stupid mode = 1                    // setting as true

Your need to replace the line and test : Modem = /dev/ttyUSB1

again suppose your possible devices are : ttyUSB0 ttyUSB1 ttyUSB2 now we need to replace the line (/dev/ttyUSB1) with ttyUSB0 then run test using wvconf then USB2 then USB3.(I hope) To automate the process use this script

#your commands to load device file
array=(ttyUSB0 ttyUSB1 ttyUSB2 ttyUSB3)
len=${#array[*]} #Number of elements of the array

while [ $i -lt $len ]; do
rep="Modem = /dev/"${array[$i]}
sed 's*Modem = /dev/tty[A-Z]\*[0-9]*'"$rep"' *'  /etc/wvdial.conf
wvdialconf #break with appropriate behavior
sleep 1
let i++

I don't have wvdial installed so i don't know what will happen if wvdialconf accept the device. This script must need to run with root permission.

share|improve this answer
Thanks for your reply。actually,after run the wvdialconf ,the right device is already written into the wvdialconf.conf. – HexForFun Jan 5 '12 at 1:35
what happen if you run this bash file? change the tty. list in code as you want. – shantanu Jan 9 '12 at 5:08

I use this script to get Data and Control ports for 3g usb dongle.


. /usr/share/libubox/

for a in `ls /sys/bus/usb/devices`; do
    local vendor product
    [ -z "$usb" -a -f /sys/bus/usb/devices/$a/idVendor -a -f /sys/bus/usb/devices/$a/idProduct ] || continue
    vendor=$(cat /sys/bus/usb/devices/$a/idVendor)
    product=$(cat /sys/bus/usb/devices/$a/idProduct)
    echo Vendor $vendor, Product $product
    [ -f /lib/network/wwan/$vendor:$product ] && {
        echo usb: $usb devicename: $devicename

[ -n "$usb" ] && {
    local old_cb control data

    json_set_namespace wwan old_cb
    json_load "$(cat $usb)"
    echo "$(cat $usb)"

    json_get_vars desc control data
    json_set_namespace $old_cb

    [ -n "$control" -a -n "$data" ] && {
        ttys=$(ls -d /sys/bus/usb/devices/$devicename/${devicename}*/tty* | sed "s/.*\///g" | tr "\n" " ")

        ctl_device=$(echo $ttys | cut -d" " -f $((control + 1)))
        [ -n "$ctl_device" ] && ctl_device=/dev/$ctl_device
        dat_device=$(echo $ttys | cut -d" " -f $((data + 1)))
        [ -n "$dat_device" ] && dat_device=/dev/$dat_device
        echo control_device: $ctl_device, data_device: $dat_device

Sample outputs:

Connected ZTE MF667

Vendor 1a40, Product 0101 #this is usb hub
Vendor 19d2, Product 0016
usb: /lib/network/wwan/19d2:0016 devicename: 1-1.2
        "desc": "ONDA MF110/ZTE",
        "control": 1,
        "data": 2
control_device: /dev/ttyUSB1, data_device: /dev/ttyUSB2

Connected Huawei E3131

Vendor 1a40, Product 0101 #this is usb hub
Vendor 12d1, Product 1506
usb: /lib/network/wwan/12d1:1506 devicename: 1-1.2
        "desc": "Huawei E367/E398",
        "control": 2,
        "data": 0
control_device: /dev/ttyUSB2, data_device: /dev/ttyUSB0
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.