• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 634
  • Last Modified:

Internet Connection Speed Command Line

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@xxxxx.net\" \"xxxxx\" /PHONE:";
            syscall += argMap["-phone"];
            syscall += " >> dial.echo";
      system( syscall.c_str() );

      ofstream c_deck( "c_deck", ios::out );
      c_deck << "deck on!" << endl;
  • 5
  • 3
  • 2
1 Solution
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...
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()' (http://msdn.microsoft.com/en-us/library/aa377004(VS.85).aspx) API which provides the means to connect programmatically. See also the sample at http://www.codeproject.com/KB/IP/dialup.aspx ("Opening a Dial-Up connection") .
bool DialUp() 
    // Fill RASDIALPARAMS structure
    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

navolutionsAuthor Commented:
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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
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.
navolutionsAuthor Commented:
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.
You might find the following to be helpful: http://www.codeproject.com/KB/IP/rasman.aspx ("CRasMonitor v1.41") - among other things it also retrieves the connection speed.
navolutionsAuthor Commented:
Helpful if I want to make a daemon, that lacks the ability to read the information from a connection opened by another program.
navolutionsAuthor Commented:
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.
navolutionsAuthor Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now