Solved

Get IP addr.

Posted on 1998-05-30
2
375 Views
Last Modified: 2010-04-06
I need some code to get the IP addr. from a node in my network (not the node where the program runs)
0
Comment
Question by:lblack
2 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 300 total points
Comment Utility
Here's a snip from one of my units:
------------------------- snip --------------------
unit LBSNet;

interface

Uses
  Winsock, Messages,
  Windows, WinSpool, Classes, SysUtils;

Type
  TIPStruct            = Record
                      B1,
                      B2,
                      B3,
                      B4      : Byte;
                    End; (* TIPStruct *)

Procedure GetIPAddr(NodeName : String; Var IP : tIPStruct);
Function GetIPAddrAsString(NodeName : String) : String;
Function GetNodeName : String;
Function GetUserName : String;
Function IPMatch(IP1, IP2 : String) : Boolean;

implementation


Procedure InitWinsock;
Var
  VerReqd      : Word;
  WSAData      : TWSAData;
  WSErr      : Word;
Begin
  VerReqd := $0101;
  WSErr := WSAStartup(VerReqd, WSAData);
End; (* Procedure InitWinsock *)

Procedure GetIPAddr(NodeName : String; Var IP : tIPStruct);
Type
  TAddrList      = Array[0..10] Of ^TInAddr;
Var
  HostEnt      : PHostEnt;
  AddrList      : ^TAddrList;
Begin
  FillChar(IP, SizeOf(IP), 0);
  HostEnt := GetHostByName(PChar(NodeName));
  If HostEnt <> nil Then
  Begin
    AddrList := Pointer(HostEnt.H_Addr_List);

    With AddrList[0]^.S_un_b, IP Do
    Begin
      B1 := Byte(S_B1);
      B2 := Byte(S_B2);
      B3 := Byte(S_B3);
      B4 := Byte(S_B4);
    End; (* With *)
  End; (* If HostEnt <> nil *)
End; (* Procedure GetIPAddr *)

Function GetIPAddrAsString(NodeName : String) : String;
Var
  IP      : tIPStruct;
Begin
  GetIPAddr(NodeName, IP);
  With IP Do
    Result := IntToStr(B1) + '.' + IntToStr(B2) + '.' + IntToStr(B3) +
            '.' + IntToStr(B4);
End; (* Function GetIPAddrAsString *)

Function GetNodeName : String;
Var
  NName      : PChar;
  NNLen      : DWord;
Begin
  NName := StrAlloc(129);
  NNLen := 128;
  GetComputerName(NName, NNLen);
  Result := NName;
  StrDispose(NName);
end;

Function GetUserName : String;
Var
  NName      : PChar;
  NNLen      : DWord;
Begin
  NName := StrAlloc(129);
  NNLen := 128;
  Windows.GetUserName(NName, NNLen);
  Result := NName;
  StrDispose(NName);
end;


Begin
  InitWinSock;
end.

0
 

Author Comment

by:lblack
Comment Utility
Quick answer, thanx
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

11 Experts available now in Live!

Get 1:1 Help Now