Solved

Get IP addr.

Posted on 1998-05-30
2
403 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 125
Delphi XE10 Round Image 2 231
firemonkey keyboard covers the controls 1 83
Delphi Firemonkey : user drawing in window 3 59
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

710 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