Solved

Router Uptime.

Posted on 2006-07-18
21
471 Views
Last Modified: 2010-04-05
Hi.

How can i get router uptime ?
0
Comment
Question by:CodedK
  • 11
  • 6
  • 3
  • +1
21 Comments
 
LVL 28

Assisted Solution

by:ciuly
ciuly earned 165 total points
ID: 17129040
I would look at SNMP (Simple Network Management Protocol). I found this program that you can look into for information: http://snmprg.sourceforge.net/
it might help, I didn't check.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17129052
Thanks ciuly, i'll check it.
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 165 total points
ID: 17135480
some routers support telnet, and you can usually find this information with a simple command
What make is the router, or are you looking for a more generic solution?
0
 
LVL 16

Author Comment

by:CodedK
ID: 17136548
Hi theRealLoki, please tell me the commands .
0
 
LVL 26

Assisted Solution

by:Russell Libby
Russell Libby earned 170 total points
ID: 17138172
The project mentioned above:

http://snmprg.sourceforge.net/

will only return the uptime of the computers local area network interface. (My computer | My Network places | View network connections | Select local area connection | Right click | Status | See duration item).

Unfortunately, there is no "generic" solution for determining a router's uptime. Some routers will allow telnet, but many do not. Most allow http/https management, but the layout of the pages is wildly different from one manufacturer to another. Then there is the issue that some routers, eg (I can speak from experience) the older WRT54G from Linksys does not support any uptime information in the firmware. Can't say about the latest models though.
Point is, not all routers even HAVE an uptime in the firmware, couple that with the fact that interfacing directly with the device requires different protocols depending on vendor, along with the lack of any common standards, and the best you could hope for is developing something that worked specifically for your router.

Regards,
Russell



0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17142088
>Hi theRealLoki, please tell me the commands .
I need to know what router it is
for mine,
i go
telnet 102.32.0.10
"username"
"password"
"1"
try it in dos first and see if you have the info in there you need

Russel, yes i know this, this is why I asked if he wanted a generic method, and what his router was...
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142121
>> Whats "1" ?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17142135

The post was mainly for CodedK's benefit, so it was understood that a generic method (for all routers) was not possible, at least not very easily.

Btw, is the IP addr you list in your example just an example? (its not in the private range of 10.x.x.x or 192.x.x.x) Just curious....

Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142233
Ok mine differs a little.
I got a "menu" command.
I got in and saw that no uptime info is available on general info menu.
Nevertheless on the browser page i can see info like uptime and other things that dont exist in telnet command.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
This all question thing was more about GetAdapterInfo.
I wanted to know just one thing... a list of what GetAdapterInfo can bring...

I've managed to gather this info :

interface caption
index of the interfaces
type of interface
max transmission unit
speed of the interfaces
length of physical address
physical address of adapter
administrative status
operational status
read time operational status changed
octets received
unicast packets received
non unicast packets received
received packets discarded
erroneous packets received
unknown protocol packets received
octets sent
unicast packets sent
non unicast packets sent
outgoing packets discarded
erroneous packets sent
output queue length
length of bDescr more member
interface description
Address
If DHCP Enabled
Current Ip Address
Ip Address List
Gateway List
DHCP Server
Have Wins
Primary Wins Server
Secondary Wins Server
Lease Obtained
Lease Expires
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Is there anything more info i can get ????

Some of that info raise errors, some not.
I thought that uptime would be easy to get...
I see that this is not the case...  :)

0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 17142371
if snmp is not an option, and you don't mind this solution only working for your particular router, then you can use TIdHTTP and login to the router's web interface and scrape the uptime off that page.
rllibby should be able to point you in the right direction on how to do that... it's not something I've had much experience with :-)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:Russell Libby
ID: 17142375

The list of the field elements and their descriptions for the return buffer from GetAdaptersInfo can be found here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/ip_adapter_info.asp

This data only applies to the PC's network adapter interface. As to the router, have you Googled your router brand to see if you can locate any info regarding the command set available via remote admin?

Russell
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142379
Its generic or nothing.... I dont want this app to work only in my pc. :)
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142393
Wait a second Russell ... I am lost here :)
>>This data only applies to the PC's network adapter interface
I've connected my modem/router through usb and i get this info through getadaptersinfo.
I get all the adapters in my pc along with my modem... And i can get all that info like that.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142399
I know that if i connect it through the lan card i wont see the router any more...
I will only see my lan card...Is that right ?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17142437
This should clear some of the confusion up:

- go to cmd prompt
- type > ipconfig /all
- read the results

This is the info you will get back from GetAdaptersInfo. It has nothing to do with the router and everything to do with the network interfaces. (be it usb, modem, loopback interface, or lan card). The only thing even related to the router will be the DHCP info, if your router is set up to hand out dynamic ip's

Russell

0
 
LVL 16

Author Comment

by:CodedK
ID: 17142472
Where is the ball...?

Ok sorry for the mess i made :)
Lets say that i wanted to ask how can i get network adapter uptime :P
does this change anything or not ?
0
 
LVL 16

Author Comment

by:CodedK
ID: 17142558
Thank you for the time and sorry for the mess :)
Increasing and splitting...
(Although i didnt understand much :) ) anyway thank you all for you time.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17151209

>> Lets say that i wanted to ask how can i get network adapter uptime :P
>> does this change anything or not ?

Absolutely. This information is available for each of the network interfaces on the PC, and this functionality works with Win98 on up. The only "undocumented" aspect is how to take the dwLastChange field and convert it into something meaningful, which I have done for you.

Enjoy,
Russell

----

program Project1;

{$APPTYPE CONSOLE}

////////////////////////////////////////////////////////////////////////////////
//   Include Units (IP Helper units: ftp://delphi-jedi.org/api/IPHlpAPI.zip)
////////////////////////////////////////////////////////////////////////////////
uses
  Windows,
  SysUtils,
  WinSock,
  WinInet,
  IpExport,
  IpHlpApi,
  IpTypes,
  IpIfConst,
  IpRtrMib;

// Totally undocumented as to how you take the DWORD value and convert it into a useable date time value.
function LastChangeTimeToDateTime(ChangeTime: DWORD): TDateTime;
var  lpSysTime:     TSystemTime;
     lpFileTime:    TFileTime;
begin

  // Get system time as file time
  GetSystemTimeAsFileTime(lpFileTime);

  // Convert to useable format
  Int64(lpFileTime):=Int64(lpFileTime)  div 100000;

  // Check low part of date against change time
  if (lpFileTime.dwLowDateTime < ChangeTime) then Dec(lpFileTime.dwHighDateTime);

  // Set new low part
  lpFileTime.dwLowDateTime:=ChangeTime;

  // Convert back to 100-nanosecond intervals
  Int64(lpFileTime):=Int64(lpFileTime) * 100000;

  // Convert result to local time
  FileTimeToLocalFileTime(lpFileTime, lpFileTime);

  // Convert to system time
  FileTimeToSystemTime(lpFileTime, lpSysTime);

  // Convert to delphi date time
  result:=SystemTimeToDateTime(lpSysTime);

end;

var
  lpIfTable:     PMibIfTable;
  dtElapse:      TDateTime;
  wDays:         Word;
  wTime:         Array [0..3] of Word;
  dwSize:        DWORD;
  dwIndex:       DWORD;

begin

  dwSize:=0;
  lpIfTable:=nil;
  if (GetIfTable(lpIfTable, dwSize, False) = ERROR_INSUFFICIENT_BUFFER) and (dwSize > 0) then
  begin
     lpIfTable:=AllocMem(dwSize);
     try
        if (GetIfTable(lpIfTable, dwSize, True) = ERROR_SUCCESS) and (lpIfTable^.dwNumEntries > 0) then
        begin
           for dwIndex:=0 to Pred(lpIfTable^.dwNumEntries) do
           begin
              // Display the interface description
              WriteLn(PChar(@lpIfTable^.table[dwIndex].bDescr));
              // Display the last change time
              dtElapse:=Now-LastChangeTimeToDateTime(lpIfTable^.table[dwIndex].dwLastChange);
              // Decode days
              wDays:=Trunc(dtElapse);
              // Remove days
              dtElapse:=dtElapse - wDays;
              // Decode time
              DecodeTime(dtElapse, wTime[0], wTime[1], wTime[2], wTime[3]);
              // Check days
              if (wDays > 0) then
                 // Print with days
                 WriteLn('Duration : ', wDays, ' days, ', Format('%.2d:%.2d:%.2d', [wTime[0], wTime[1], wTime[2]]))
              else
                 // Print without days
                 WriteLn('Duration : ', Format('%.2d:%.2d:%.2d', [wTime[0], wTime[1], wTime[2]]));
              // Space
              WriteLn;
           end;
        end;                                
     finally
        FreeMem(lpIfTable);
     end;
  end;
  ReadLn;

end.
0
 
LVL 16

Author Comment

by:CodedK
ID: 17152183
Thank you Russell, i really wanted to ask that :
>>dwLastChange field and convert it into something meaningful

I thought that i was doing something wrong and i got this @#%@# values.

I also thought that since i got my router name(Description = SpeedTouch) among the list of Network Adapters
then a Modem/Router=a Network adapter. This is what i dont understand.

Thank you very much :)
0
 
LVL 16

Author Comment

by:CodedK
ID: 17152490
Russell i've tried it...
For all network adapters (including my SpeedTouch) it shows the time that windows started.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17153079

Yep, thats usually the case. In case you curious, go to the following:

- My Computer
- My Network Places
- View Network Connections
- Select a connection
- Right Click
- Select Status
- Check the duration

If you want to test my program, disable then renable the connection and check again

Russell


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

9 Experts available now in Live!

Get 1:1 Help Now