Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get IP addr.

Posted on 1998-05-30
2
Medium Priority
?
416 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 1200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

661 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