Solved

Get IP addr.

Posted on 1998-05-30
2
411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
BlackMan earned 300 total points
ID: 1349317
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
ID: 1349318
Quick answer, thanx
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.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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