[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to get server or localhost address in VB.net Win32 application.

Posted on 2004-11-22
4
Medium Priority
?
1,583 Views
Last Modified: 2008-01-09
Hi..

How do i get a server IP address in VB.net win32 application.

Thanks !
0
Comment
Question by:dynamicrevolutions
  • 2
4 Comments
 

Accepted Solution

by:
pfransson earned 1500 total points
ID: 12642790
Hi,

Is this what you are looking for?

Imports System.Net
Public Class cslGetServer


    Shared Function returnAddressOnNetwork(ByVal hn As String) As String
        Dim ia As String
        Try
            'Returns the IP address of the host computer as a string.
'actually only the first IP address. Access array if the server has more than one interface.
            ia = Dns.GetHostByName(hn).AddressList(0).ToString
            Return ia
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Function



End Class

How to call:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'call using namespace.classname.function name passing hostname to function
        Dim str As String = ipResolver.cslGetServer.returnAddressOnNetwork("mail.webhost4life.com")
        MessageBox.Show(Str)
    End Sub

I hope this helped.


0
 
LVL 4

Expert Comment

by:bhpr
ID: 12642808
Hi dynamicrevolutions,

try this...

Import System.Net

 Dim ipEntry As IPHostEntry = Dns.GetHostByName(Environment.MachineName)
 Dim IpAddr As IPAddress() = ipEntry.AddressList
 Dim i As Integer

 'A hostmachine can have more than one IP assigned

  Me.Label2.Text = IpAddr(0).ToString()

-bhpr
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12642818
hey..

check if this is what you are looking for..

        Dim ip As System.Net.IPHostEntry
        ip = System.Net.Dns.GetHostByName("<server name>")
        MsgBox(ip.AddressList(0).ToString) 'will display the first IP assigned


you might hav eto add error checks

Enjoy!
Pratap
0
 
LVL 11

Expert Comment

by:pratap_r
ID: 12642826
oops.. sorry guys.. i din't notice your posts..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this post we will learn different types of Android Layout and some basics of an Android App.
No other job is as rewarding and demanding as building an iPhone app is. It is not really in the hands of the developer for the success of an iPhone app. Many factors operate jointly for every iOS application's success in the market.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Loops Section Overview

612 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