Router Uptime.

Hi.

How can i get router uptime ?
LVL 16
CodedKAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
TheRealLokiConnect With a Mentor Senior DeveloperCommented:
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
 
2266180Connect With a Mentor Commented:
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
 
CodedKAuthor Commented:
Thanks ciuly, i'll check it.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
CodedKAuthor Commented:
Hi theRealLoki, please tell me the commands .
0
 
Russell LibbyConnect With a Mentor Software Engineer, Advisory Commented:
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
 
TheRealLokiSenior DeveloperCommented:
>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
 
CodedKAuthor Commented:
>> Whats "1" ?
0
 
Russell LibbySoftware Engineer, Advisory Commented:

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
 
CodedKAuthor Commented:
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
 
TheRealLokiSenior DeveloperCommented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:

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
 
CodedKAuthor Commented:
Its generic or nothing.... I dont want this app to work only in my pc. :)
0
 
CodedKAuthor Commented:
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
 
CodedKAuthor Commented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:
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
 
CodedKAuthor Commented:
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
 
CodedKAuthor Commented:
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
 
Russell LibbySoftware Engineer, Advisory Commented:

>> 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
 
CodedKAuthor Commented:
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
 
CodedKAuthor Commented:
Russell i've tried it...
For all network adapters (including my SpeedTouch) it shows the time that windows started.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.