Internet Connection Speed Command Line

Posted on 2009-12-18
Last Modified: 2012-05-08
I make a program that connects to a dialup modem via command line rasdial entriy \Phone:xxx-xxxx and now I would like to get the connection speed. I have looked every where for a solution, I tryed to use c++ to RasEnumConnections but it says there are no connections when I know there is one active. Here is the code I use to establish the connection:

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <map>
#include <string>
#include <ras.h>
#include <raserror.h>
using namespace std;

#pragma comment( lib, "rasapi32")

int main( int argc, char *argv[] ){
      map<string,string> argMap;
      int maxArg = argc - 1;
      argc = 0;
      while( argc++ < maxArg ){
            argMap[*argv++] = *argv++;

      ofstream decho( "dial.echo", ios::trunc );

      string syscall = "rasdial.exe copper_auto ";

      if( argMap["-phone"] == "logoff" ){
            syscall += " /DISCONNECT";
            syscall += " >> dial.echo";
            syscall += " \"\" \"xxxxx\" /PHONE:";
            syscall += argMap["-phone"];
            syscall += " >> dial.echo";
      system( syscall.c_str() );

      ofstream c_deck( "c_deck", ios::out );
      c_deck << "deck on!" << endl;
Question by:navolutions
    LVL 17

    Expert Comment

    Simply put a file in your website, like 10 or 100kb file, Do GetTickCount, then start downloading, after download done, GetTickCount again and compare, then divide file size, like 100,000 (100kb) to TickCount difference. You'll get download rate...
    LVL 86

    Accepted Solution

    Well if you connect via the Windows API, you will receive the connection handle and then can inquire whatevr infio you need to know - there's the 'RasDial()' ( API which provides the means to connect programmatically. See also the sample at ("Opening a Dial-Up connection") .
    bool DialUp() 
        // Fill RASDIALPARAMS structure
        RASDIALPARAMS rdParams;
        rdParams.dwSize = sizeof(RASDIALPARAMS);
        rdParams.szEntryName[0] = '\0';
        lstrcpy(rdParams.szPhoneNumber, szPhoneNumberToDial);
        rdParams.szCallbackNumber[0] = '\0';
        lstrcpy( rdParams.szUserName, szUserName );
        lstrcpy( rdParams.szPassword, szPassword );    
        rdParams.szDomain[0] = '\0';
        HRASCONN hRasConn = NULL;
        DWORD dwRet = RasDial( NULL, NULL, &rdParams, 0L, NULL, &hRasConn );
        // Everything OK?
        if (dwRet == 0)  
            return true;    
        // Error occurred - get error description and alert user
        char  szBuf[256];
        if (RasGetErrorString( (UINT)dwRet, (LPSTR)szBuf, 256 ) != 0 )
            wsprintf( (LPSTR)szBuf, "Undefined RAS Dial Error (%ld).", dwRet );
        RasHangUp( hRasConn );
        AfxMessageBox( NULL, (LPSTR)szBuf, "Error", MB_OK | MB_ICONSTOP );
        return false;

    Open in new window


    Author Comment

    Using the method described by jkr I only be able to see the initial connection speed, and would be in the dark if the connection was being interrupted. Because I want the dialup to persist past my application, otherwise I would have to make a daemon. Which I don't want to do.
    Using the method by CSecurity I would need another application to check internet connection speed, which might be the way I have to go but that is not a solution that is a work around.
    LVL 17

    Expert Comment

    You don't need another application, in your application I mean VB6, write a function which downloads some data from for example Google, then see how much was it's size and calculate the time it took... That's all
    LVL 86

    Expert Comment

    How are you querying the connection speed at the moment? You should be able to do that subsequently at any later time also, given that the handle is still valid.

    Author Comment

    that is VB6 and my application is in c++, and as far as setting up to download a file from running my app on a windows PC takes out the system call for wget and I don't know of a similar function that runs in windows. So I would have to open up a winsock connection of which I have broadband running at the same time so I would have to push it from the dialup connection and if I can't get my dialup handle with out a daemon that dose not help.

    I have no way of getting the connection speed at this point. But as far as handle, it is lost when the application closes and the methods that you describe don't work and retrieving it at a later time. As I said in my earlier post.
    LVL 86

    Expert Comment

    You might find the following to be helpful: ("CRasMonitor v1.41") - among other things it also retrieves the connection speed.

    Author Comment

    Helpful if I want to make a daemon, that lacks the ability to read the information from a connection opened by another program.

    Author Comment

    Still have no solution outside making a persistent program to both create and track the connection speed, or only have the ability to check the speed when the connection is initialized. Because the program I am making is not the one using the dial-up connection it is only initializing it. But even if I make the Ras connection with the program when it exsits there is no way for me to get that connection handle that I am aware of.

    Author Closing Comment

    It dose give the connection speed of the connection once it is opened, not after the program closes unless i made it a persistent program. So the delma of having to write a persistent program is still very valid and I did wait to hear a better answer but it don't seem there is one.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now