VB doubt


Does someone know how this can be done?

i want to enter a host name  through a input edit box

then i want to ping the host name using a command line so that i can retrieve the ip adress of that machine.

so that

vv.xx.yy.zz  hostname in the 'hosts' file at

C:\WINDOWS\system32\drivers\etc

basically the problem is that is there some way so that  

i can accept the host name from the user.
then find the ip address of that machine using say

ping hostname.com????????

is there any other way i can obtain the ip of the machine.

and add the entry to hosts file  as above.


i have the code that writes to the hosts file .

i want some way to obtain the ip of the machine, given the host name in my application .



i know this seems tough. Can you help me with this.













VlearnsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
See:

How to Ping an IP Address By Host Name
http://vbnet.mvps.org/code/internet/pingbyhostname.htm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
List244Commented:
Well, what are you trying to get the IP of?
A domain? If it is a domain you are trying
to track, you can simply connect to the
domain in place of IP, and then check
which IP you are connected to.
0
VlearnsAuthor Commented:
no actually i know machines by their names.
so abc.def.com

i want the user to type in this name and be able to retrieve their ip address. i do not know how to do that using vb

pinging might be a primitive solution.
do you know a better way?

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

computerguy801Commented:
If you are using VB.net then this is the best way:

     System.Net.Dns.GetHostByName("www.microsoft.com").AddressList(0).ToString()

This will return the IP Address of www.microsoft.com
You just input a hostname and it returns the ipaddress.
0
computerguy801Commented:
If you are using VB6 then you have to use about a million lines of code but it can be done:

This website contains all the code:

http://vbnet.mvps.org/index.html?code/network/iplookup.htm
0
David LeeCommented:
Here's a way, that doesn't require much code, to do it using WMI.  This is from Microsoft's MSDN web site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__networking.asp).

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration ")
 For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
                WScript.Echo IPConfig.IPAddress(i)
        Next
    End If
Next

0
syntaxmishapCommented:
Put the following code into a form. It uses the Winsock API to get the IP address of a host. Let me know if you have any questions.



Option Explicit

Private Declare Function gethostbyname Lib "ws2_32.dll" (ByVal host_name As String) As Long
Private Declare Function WSAStartup Lib "ws2_32.dll" (ByVal wVR As Long, lpWSAD As WSAData) As Long
Private Declare Function WSACleanup Lib "ws2_32.dll" () As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)

Private Type WSAData
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * 257
    szSystemStatus As String * 129
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As Long
End Type

Private Type HOSTENT
    hName     As Long
    hAliases  As Long
    hAddrType As Integer
    hLength   As Integer
    hAddrList As Long
End Type

Private Function sGetIPAddressOfHost(sHost As String) As String
    Dim udtHostent As HOSTENT
    Dim udtWinsockData As WSAData
    Dim lpIP As Long
    Dim lpHNet As Long
    Dim lRet As Long
    Dim abIP() As Byte
    Dim strIpAddress As String
    Dim i As Integer
    lRet = WSAStartup(&H101, udtWinsockData)
    If lRet = 0 Then
        lpHNet = gethostbyname(sHost)
        If lpHNet <> 0 Then
            RtlMoveMemory udtHostent, lpHNet, LenB(udtHostent)
            RtlMoveMemory lpIP, udtHostent.hAddrList, 4
            ReDim abIP(1 To udtHostent.hLength)
            RtlMoveMemory abIP(1), lpIP, udtHostent.hLength
            For i = 1 To udtHostent.hLength
                strIpAddress = strIpAddress & abIP(i) & "."
            Next
            strIpAddress = Left$(strIpAddress, Len(strIpAddress) - 1)
            sGetIPAddressOfHost = strIpAddress
            WSACleanup
            Exit Function
        End If
    End If
    WSACleanup
End Function

Private Sub Form_Load()
    MsgBox sGetIPAddressOfHost("google.com")
End Sub
0
VlearnsAuthor Commented:
i figured it out
thanks all
0
Ryan ChongCommented:
Hi Vlearns,

What's your solution, who make the helps here? ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.