?
Solved

how can I get default gateway?

Posted on 2005-05-15
2
Medium Priority
?
915 Views
Last Modified: 2008-02-01
I tried  some function but them dont work out.

Tell me some  function to do this after your examination!Do give me anything you haven't haven a examination! had better give me full unit and function name to use this unit after your examination!I will give everyone A grade who answer regardless of your answer is correct or not correct!
had better dont  use function of get register value
beacuse my register of gateway is strange   such: HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/{4203270B-BDAF-418B-BF41-2569770580C4}/Parameters/Tcpip/DefaultGateway
So I want such API function to get defaultgateway ,beacuse I want to get default gateway regardless of which way to register.

I have use some function:



function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  //str: string;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    RemoteHost:=Winsock.GetHostByName(buf);
    if RemoteHost=NIL then
      my_ip_address:=winsock.htonl($07000001)  (* 127.0.0.1 *)
    else
      my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
      //str:= inet_addr(pointer(RemoteHost^.h_addr_list^)^);
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  result:=winsock.ntohl(result);
  end;  


function LongToIp(Long: Longint): string;
var
  ipx: array[0..3] of Byte;
  i: Byte;
begin
  Longint(ipx) := long;
  Result       := '';
  for i := 0 to 3 do Result := Result + IntToStr(ipx[i]) + '.';
  SetLength(Result, Length(Result) - 1);
end;

but I don't have haven the correct answer from thoese two function

My Default GetWay:192.168.1.1  vpn host
my ip :192.168.1.103  in vpn
The GetWay above 192.168.1.1  :  218.86.198.1
mask:225.225.225.0
first DNS:202.98.192.68
second DNS:192.168.1.11


with the two function run

I got getway as 128.1.1.223  why?
where did 128.1.1.223 come from?

and I ping 128.1.1.223 I cant ping through it.

I can ping through 192.168.1.1  192.168.1.103   218.86.198.1 first DNS:202.98.192.68
second DNS:192.168.1.11
0
Comment
Question by:forLord
2 Comments
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 240 total points
ID: 14008321
0
 

Author Comment

by:forLord
ID: 14008731
This link is not useful to me I think

who will give me a full unit and function name to use?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 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