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

How can I get mac and subnet-mask and default getway of local computer?

use delphi
API or otherway
0
forLord
Asked:
forLord
1 Solution
 
forLordAuthor Commented:
function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  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^)^);
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  result:=winsock.ntohl(result);
  end;

How can I change the longint to ipaddress string like '192.168.1.103'?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now