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

x
?
Solved

How to get IP address of a machine in  VB

Posted on 2003-04-01
20
Medium Priority
?
725 Views
Last Modified: 2007-12-19
I want to fetch the IP address of the machine on which the programe is running and sent it in xml file
0
Comment
Question by:Malvi
[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
  • 3
  • 2
  • 2
  • +3
20 Comments
 
LVL 8

Expert Comment

by:heskyttberg
ID: 8244784
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
 
LVL 34

Expert Comment

by:arbert
ID: 8246810
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
 
LVL 24

Expert Comment

by:SunBow
ID: 8247172
done?
0
Industry Leaders: 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!

 
LVL 5

Expert Comment

by:msa2003
ID: 8248655
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
 
LVL 5

Expert Comment

by:msa2003
ID: 8251972
<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
 

Expert Comment

by:SpideyMod
ID: 8254259
I have cleaned this thread as proposed 4 days ago.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 34

Expert Comment

by:arbert
ID: 10834782
I still believe the original link I posted contained the information needed.
0
 
LVL 1

Expert Comment

by:GhostMod
ID: 10863108
PAQed - no points refunded (of 50)

GhostMod
Community Support Moderator
0
 
LVL 34

Expert Comment

by:arbert
ID: 10863180
I guess I'll quit posting any responses to cleanup requests since they always seem to be overlooked or ignored.
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 10871581
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…
Suggested Courses

721 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