?
Solved

VB doubt

Posted on 2004-11-26
9
Medium Priority
?
236 Views
Last Modified: 2013-11-13

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.













0
Comment
Question by:Vlearns
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 600 total points
ID: 12684731
See:

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

Expert Comment

by:List244
ID: 12684732
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
 

Author Comment

by:Vlearns
ID: 12684746
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:computerguy801
ID: 12684854
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
 
LVL 1

Expert Comment

by:computerguy801
ID: 12684859
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
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 400 total points
ID: 12685925
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
 
LVL 1

Assisted Solution

by:syntaxmishap
syntaxmishap earned 1000 total points
ID: 12688906
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
 

Author Comment

by:Vlearns
ID: 12995778
i figured it out
thanks all
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 12995795
Hi Vlearns,

What's your solution, who make the helps here? ;-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 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