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

How to get IP address of a machine in VB

I want to fetch the IP address of the machine on which the programe is running and sent it in xml file
0
Malvi
Asked:
Malvi
  • 3
  • 2
  • 2
  • +3
1 Solution
 
heskyttbergCommented:
Hi!

With what do you want to catch ip ?

A program ?
A asp app ?
A php app ?
A cgi app ?
A perl app web/shell ?
A C/C++ program ?

What OS MAC,Windows, Linux, Solaris ?

What OS version ?

If you mean some sort of web app use the server variables.

Regards
/Hans - Erik Skyttberg
0
 
arbertCommented:
This should do it for you:

http://www.mvps.org/vbnet/index.html?code/network/macaddress.htm


All you have to do then is open a text file and write it out in XML format.

Brett
0
 
SunBowCommented:
done?
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
msa2003Commented:
Oops...

Hans - Erik Skyttberg: Title: How to get IP address of a machine in  VB

Brett: MAC address is not the same as IP address. <Edited by SpideyMod>

SunBow: What do you mean?

Malvi: I really do not know VB... But I had written a little DLL (getip.dll) which implements the IP-determining function called GetLocalIP. It is called without parameters and returns a binary value of an IP address in right bit order. I had also written a VB module (called getip.bas) which implements an interface to the getip.dll library and declares a function GetLacalIPAsString to convert binary value to the string representation:

Attribute VB_Name = "getip"
Public Declare Function GetLocalIP Lib "getip.dll" () As Long
Public Declare Sub InitSocks Lib "getip.dll" ()
Public Declare Sub CloseSocks Lib "getip.dll" ()
Public Function GetLacalIPAsString(IP As Long) As String
  I = IP
  M = I And 255
  S = Str(M)
  For J = 1 To 3
    I = (I - M) \ 256
    M = I And 255
    S = Str(M) + "." + S
  Next
  GetLacalIPAsString = S
End Function

Function InitSocks is required to init Windows Sockets (used to determine IP) prior to run GetLocalIP. Function CloseSocks must be run at the end of the program (or subroutine) to free up Windows Sockets resources.

Here is the source code for DLL (in Delphi):

library getip;

uses
  SysUtils,
  Classes,
  WinSock;

{$R *.res}

function GetLocalIP: Integer; stdcall;
var
  Phe: PHostEnt;
  szHostName: array[0 .. 128] of Char;
begin
  GetHostName(szHostName, 128);
  Phe := GetHostByName(szHostName);
  if Phe = nil then Result := 0 else
    Result := htonl(Integer(PLongint(Phe^.h_addr_list^)^));
end;

procedure InitSocks; stdcall;
var
  wsd: TWsaData;
begin
  WsaStartup($101, wsd);
end;

procedure CloseSocks; stdcall;
begin
  WsaCleanup;
end;

exports
  GetLocalIP,
  InitSocks,
  CloseSocks;

begin
end.

Maybe the same functions could be realized with VB... I don't know. You may ask it in "Programming\Languages\VB" topic.

I had also written an VB example of getip.dll usage. You can download all sources here: http://www.serge.dsip.net/downloads/getip.zip

You need to place getip.dll DLL in your System32 folder during design/debug-time. You need to install it in the folder where your program executable is located or System32 folder at runtime.

What about XML I need a more detailed description (used XML format and what do you mean under 'send') to help you.

Best regards
Serge
0
 
msa2003Commented:
<Edited by SpideyMod>

Malvi: <Edited by SpideyMod> I still need more detailed description of your question. What did you mean under "sent it in xml file"? Do you need to send XML over network (TCP? NetBIOS? SMB? e-mail?)?
0
 
SpideyModCommented:
I have cleaned this thread as proposed 4 days ago.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
arbertCommented:
I still believe the original link I posted contained the information needed.
0
 
GhostModCommented:
PAQed - no points refunded (of 50)

GhostMod
Community Support Moderator
0
 
arbertCommented:
I guess I'll quit posting any responses to cleanup requests since they always seem to be overlooked or ignored.
0
 
GhostModCommented:
Hello all,
I will close this question according to KronosTM's suggestion; PAQ/No refund.

Please post your feelings on this closure.

Thanks,
GhostMod
CS Moderator
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now