Link to home
Start Free TrialLog in
Avatar of CodedK
CodedKFlag for Greece

asked on

Router Uptime.

Hi.

How can i get router uptime ?
SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodedK

ASKER

Thanks ciuly, i'll check it.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodedK

ASKER

Hi theRealLoki, please tell me the commands .
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>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...
Avatar of CodedK

ASKER

>> Whats "1" ?

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
Avatar of CodedK

ASKER

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...  :)

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 :-)

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
Avatar of CodedK

ASKER

Its generic or nothing.... I dont want this app to work only in my pc. :)
Avatar of CodedK

ASKER

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.
Avatar of CodedK

ASKER

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 ?
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

Avatar of CodedK

ASKER

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 ?
Avatar of CodedK

ASKER

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.

>> 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.
Avatar of CodedK

ASKER

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 :)
Avatar of CodedK

ASKER

Russell i've tried it...
For all network adapters (including my SpeedTouch) it shows the time that windows started.

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