Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP conenction details

Status
Not open for further replies.

mbrant

MIS
Aug 2, 2000
1
US
I'm trying to write a small utility for my users to enable them to tell me their IP details - something like the Win95 WINIPCFG utility. This utility is missing in Win2000.<br><br>The WINSOCK control lets me find out the IP address and the local computer name but not other details like the subnet mask and default gateway (other info such as DHCP server, DNS settings etc... would be good), or the ability to idetify the adapter the information relates to.<br><br>Is there a way to do this with VB6 (Pro) as delivered, or does any one know of a third party tool (prefferably freeware or shareware - this is a one of project) that will enable me to get at this information.
 
Hey,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I found this API on MSDN. DnsQueryConfig.&nbsp;&nbsp;Just search MSDN for more info.&nbsp;&nbsp;I believe it will only work on Win2000. <br><br> <p>Clayton T. Paige<br><a href=mailto:cpaige@home.com>cpaige@home.com</a><br><a href= Snail</a><br>Clayton T. Paige<br>
Programmer Extraordinaire <br>
========================================================<br>
"Who General Failure? and Why is he reading my disk drive?
 
msinfo32.exe will show you information about your network settings under Components\Network\Adapter
 
The following functions will return <i>some</i> of the information you require. A little research on the APIs should get you more.<br><FONT FACE=monospace><br>Option Explicit <br><br>Const MAX_WSADescription = 256 <br>Const MAX_WSASYSStatus = 128 <br>Const ERROR_SUCCESS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Long = 0 <br>Const WS_VERSION_REQD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Long = &H101 <br>Const WS_VERSION_MAJOR&nbsp;&nbsp;&nbsp;&nbsp;As Long = WS_VERSION_REQD \ &H100 And &HFF& <br>Const WS_VERSION_MINOR&nbsp;&nbsp;&nbsp;&nbsp;As Long = WS_VERSION_REQD And &HFF& <br>Const MIN_SOCKETS_REQD&nbsp;&nbsp;&nbsp;&nbsp;As Long = 1 <br>Const SOCKET_ERROR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Long = -1 <br><br>Private Type HOSTENT <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Long <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hAliases&nbsp;&nbsp;&nbsp;As Long <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hAddrType&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hLen&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hAddrList&nbsp;&nbsp;As Long <br>End Type <br>Private Type WSADATA <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wVersion&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wHighVersion&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szDescription(0 To MAX_WSADescription)&nbsp;&nbsp;&nbsp;As Byte <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szSystemStatus(0 To MAX_WSASYSStatus)&nbsp;&nbsp;&nbsp;&nbsp;As Byte <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wMaxSockets&nbsp;&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wMaxUDPDG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;As Integer <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dwVendorInfo&nbsp;&nbsp;As Long <br>End Type <br><br>Private Declare Function WSAGetLastError Lib _<br>&nbsp;&quot;WSOCK32.DLL&quot; () As Long <br>Private Declare Function WSAStartup Lib _ <br>&nbsp;&quot;WSOCK32.DLL&quot; (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long <br>Private Declare Function WSACleanup Lib _ <br>&nbsp;&quot;WSOCK32.DLL&quot; () As Long <br>Private Declare Function gethostname Lib _ <br>&nbsp;&quot;WSOCK32.DLL&quot; (ByVal szHost As String, _ <br>&nbsp;ByVal dwHostLen As Long) As Long <br>Private Declare Function gethostbyname Lib _ <br>&nbsp;&quot;WSOCK32.DLL&quot; (ByVal szHost As String) As Long <br>Private Declare Sub CopyMemory Lib _ <br>&nbsp;&quot;kernel32&quot; Alias &quot;RtlMoveMemory&quot; (hpvDest As Any, _ <br>&nbsp;ByVal hpvSource As Long, ByVal cbCopy As Long) <br>&nbsp;&nbsp;&nbsp;&nbsp;<br>Private Function GetIPAddress() As String <br>Dim sHostName&nbsp;&nbsp;As String * 256 <br>Dim lpHost As Long <br>Dim HOST&nbsp;&nbsp;As HOSTENT <br>Dim dwIPAddr As Long <br>Dim tmpIPAddr() As Byte <br>Dim i As Integer <br>Dim sIPAddr As String <br>&nbsp;&nbsp;&nbsp;&nbsp;<br>If Not SocketsInitialize() Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetIPAddress = &quot;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>If gethostname(sHostName, 256) = SOCKET_ERROR Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetIPAddress = &quot;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Windows Sockets error &quot; & _ <br>&nbsp;Str$(WSAGetLastError()) & &quot; has occurred.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketsCleanup <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>sHostName = Trim$(sHostName) <br>lpHost = gethostbyname(sHostName) <br>If lpHost = 0 Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetIPAddress = &quot;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Windows Sockets are not responding.&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketsCleanup <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>CopyMemory HOST, lpHost, Len(HOST) <br>CopyMemory dwIPAddr, HOST.hAddrList, 4 <br>ReDim tmpIPAddr(1 To HOST.hLen) <br>CopyMemory tmpIPAddr(1), dwIPAddr, HOST.hLen <br>For i = 1 To HOST.hLen <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sIPAddr = sIPAddr & tmpIPAddr(i) & &quot;.&quot; <br>Next <br>GetIPAddress = Mid$(sIPAddr, 1, Len(sIPAddr) - 1) <br>SocketsCleanup <br>End Function <br><br>Private Function GetIPHostName() As String <br>Dim sHostName As String * 256 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>If Not SocketsInitialize() Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetIPHostName = &quot;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>If gethostname(sHostName, 256) = SOCKET_ERROR Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetIPHostName = &quot;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Windows Sockets error &quot; & _ <br>Str$(WSAGetLastError()) & &quot; has occurred.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketsCleanup <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>GetIPHostName = Left$(sHostName, _ <br>&nbsp;InStr(sHostName, Chr(0)) - 1) <br>SocketsCleanup <br>End Function <br><br>Private Function HiByte(ByVal wParam As Integer) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HiByte = wParam \ &H100 And &HFF& <br>End Function <br><br>Private Function LoByte(ByVal wParam As Integer) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LoByte = wParam And &HFF& <br>End Function <br><br>Private Sub SocketsCleanup() <br>If WSACleanup() &lt;&gt; ERROR_SUCCESS Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Socket error occurred in Cleanup.&quot; <br>End If <br>End Sub <br><br>Private Function SocketsInitialize() As Boolean <br>Dim WSAD As WSADATA <br>Dim sLoByte As String <br>Dim sHiByte As String <br>&nbsp;&nbsp;&nbsp;&nbsp;<br>If WSAStartup(WS_VERSION_REQD, WSAD) &lt;&gt; ERROR_SUCCESS Then <br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;The 32-bit Windows Socket is not responding.&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;SocketsInitialize = False <br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>If WSAD.wMaxSockets &lt; MIN_SOCKETS_REQD Then <br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;This application requires a minimum of &quot; & _ <br>&nbsp;CStr(MIN_SOCKETS_REQD) & &quot; supported sockets.&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketsInitialize = False <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>If LoByte(WSAD.wVersion) &lt; WS_VERSION_MAJOR Or _ <br>&nbsp;(LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And HiByte _ <br>(WSAD.wVersion) &lt; WS_VERSION_MINOR) Then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sHiByte = CStr(HiByte(WSAD.wVersion)) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sLoByte = CStr(LoByte(WSAD.wVersion)) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Sockets version &quot; & sLoByte & &quot;.&quot; & _ <br>sHiByte & &quot; is not supported by 32-bit Windows Sockets.&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SocketsInitialize = False <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function <br>End If <br>SocketsInitialize = True <br>End Function <br><br>Private Sub Form_Load() <br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;IPHostName=&quot; & GetIPHostName & vbCrLf &&nbsp;&nbsp;_ <br>&quot;IPAddress=&quot; & GetIPAddress <br>End Sub <br><FONT FACE=monospace><br><br>Hope that helped a little.<br><br> <p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top