| VB 源码 | VC 源码 | ASP源码 | JSP源码 | PHP源码 | CGI源码 | FLASH源码 | 素材模板 | C 源程序 | 站长工具 | 站长教程 |

VB技术

ASP技术
PHP技术
JSP技术
VB技术
.NET技术

本类阅读TOP10

·VB到底为我们做了什么?
·利用shell编程实现DOS风格的Linux命令行
·屏保程序模板化完整源代码
·用VB6实现中英文文本的私钥加密
·VB解决Unicode文本转换的问题
·用VB编写网络监控软件
·一组VB实用小程序
·新手必学:windows网络编程经典入门
·用VB编写定时关闭计算机的程序
·用VB制作屏幕保护程序

站内搜索

VB枚举主机IP

  在窗体上加入下列控件TextBox:Text1,ListBox:List1,CommandButton:Command1

  在窗体上加入如下代码:

  '--------------------------Form1---------------------------------
  Option Explicit

  Private Function HiByte(ByVal wParam As Integer)
  HiByte = wParam \ &H100 And &HFF&
  End Function

  Private Function LoByte(ByVal wParam As Integer)
  LoByte = wParam And &HFF&
  End Function

  Private Sub SocketsCleanup()
  If WSACleanup() <> ERROR_SUCCESS Then
  MsgBox "Socket error occurred in Cleanup."
  End If
  End Sub
  Private Function SocketsInitialize() As Boolean
  Dim WSAD As WSAData
  Dim sLoByte As String
  Dim sHiByte As String
  If WSAStartup(WS_VERSION_REQD, WSAD) <> ERROR_SUCCESS Then
  MsgBox "The 32-bit Windows Socket is not responding."
  SocketsInitialize = False
  Exit Function
  End If
  If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
  MsgBox "This application requires a minimum of " & CStr(MIN_SOCKETS_REQD) & " supported sockets."
  SocketsInitialize = False
  Exit Function
  End If
  If LoByte(WSAD.wVersion) < WS_VERSION_MAJOR Or (LoByte(WSAD.wVersion) = WS_VERSION_MAJOR And HiByte(WSAD.wVersion) < WS_VERSION_MINOR) Then
  sHiByte = CStr(HiByte(WSAD.wVersion))
  sLoByte = CStr(LoByte(WSAD.wVersion))
  MsgBox "Sockets version " & sLoByte & "." & sHiByte & " is not supported by 32-bit Windows Sockets."
  SocketsInitialize = False
  Exit Function
  End If
  SocketsInitialize = True
  End Function

  Private Function GetName() As String
  Dim sHostName As String * 256
  If Not SocketsInitialize() Then
  GetName = ""
  Exit Function
  End If
  If gethostname(sHostName, 256) = SOCKET_ERROR Then
  GetName = ""
  MsgBox "Windows Sockets error Unable to successfully get Host Name."
  SocketsCleanup
  Exit Function
  End If
  GetName = Left$(sHostName, InStr(sHostName, Chr(0)) - 1)
  SocketsCleanup
  End Function

  Private Sub GetHostIP()
  Dim I As Integer
  If Not SocketsInitialize() Then
  MsgBox "Windows Sockets error"
  Exit Sub
  End If
  Dim lngPtrToHOSTENT As Long
  Dim udtHostent As HOSTENT
  Dim lngPtrToIP As Long
  Dim arrIpAddress() As Byte
  Dim strIpAddress As String
  List1.Clear
  lngPtrToHOSTENT = gethostbyname(Trim$(Text1.Text))
  If lngPtrToHOSTENT = 0 Then
  MsgBox "Windows Sockets error Unable to successfully get Host Ip."
  Else
  RtlMoveMemory udtHostent, lngPtrToHOSTENT, LenB(udtHostent)
  RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
  Do Until lngPtrToIP = 0
  ReDim arrIpAddress(1 To udtHostent.hLength)
  RtlMoveMemory arrIpAddress(1), lngPtrToIP, udtHostent.hLength
  For I = 1 To udtHostent.hLength
  strIpAddress = strIpAddress & arrIpAddress(I) & "."
  Next
  strIpAddress = Left$(strIpAddress, Len(strIpAddress) - 1)
  List1.AddItem strIpAddress
  strIpAddress = ""
  udtHostent.hAddrList = udtHostent.hAddrList + LenB(udtHostent.hAddrList)
  RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
  Loop
  End If
  SocketsCleanup

  End Sub

  Private Sub Command1_Click()
  GetHostIP
  End Sub

  Private Sub Form_Load()
  Text1.Text = GetName
  End Sub
  '----------------------------end Form1----------------------------------
  在模块部分添加
  '----------------------------Module1------------------------------------
  Option Explicit

  Public Const INADDR_NONE = &HFFFF
  Public Const SOCKET_ERROR = -1
  Public Const WSABASEERR = 10000
  Public Const WSAEFAULT = (WSABASEERR + 14)
  Public Const WSAEINVAL = (WSABASEERR + 22)
  Public Const WSAEINPROGRESS = (WSABASEERR + 50)
  Public Const WSAENETDOWN = (WSABASEERR + 50)
  Public Const WSASYSNOTREADY = (WSABASEERR + 91)
  Public Const WSAVERNOTSUPPORTED = (WSABASEERR + 92)
  Public Const WSANOTINITIALISED = (WSABASEERR + 93)
  Public Const WSAHOST_NOT_FOUND = 11001
  Public Const WSADESCRIPTION_LEN = 257
  Public Const WSASYS_STATUS_LEN = 129
  Public Const WSATRY_AGAIN = 11002
  Public Const WSANO_RECOVERY = 11003
  Public Const WSANO_DATA = 11004
  Public Const WS_VERSION_REQD As Long = &H101
  Public Const ERROR_SUCCESS = 0
  Public Const MIN_SOCKETS_REQD As Long = 1
  Public Const WS_VERSION_MAJOR As Long = WS_VERSION_REQD \ &H100 And &HFF&
  Public Const WS_VERSION_MINOR As Long = WS_VERSION_REQD And &HFF&

  Public Type WSAData
  wVersion As Integer
  wHighVersion As Integer
  szDescription As String * WSADESCRIPTION_LEN
  szSystemStatus As String * WSASYS_STATUS_LEN
  iMaxSockets As Integer
  iMaxUdpDg As Integer
  lpVendorInfo As Long
  End Type

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

  Public Type servent
  s_name As Long
  s_aliases As Long
  s_port As Integer
  s_proto As Long
  End Type

  Public Type protoent
  p_name As String 'Official name of the protocol
  p_aliases As Long 'Null-terminated array of alternate names
  p_proto As Long 'Protocol number, in host byte order
  End Type

  Public Declare Function WSAStartup _
  Lib "ws2_32.dll" (ByVal wVR As Long, lpWSAD As WSAData) As Long

  Public Declare Function WSACleanup Lib "ws2_32.dll" () As Long

  Public Declare Function gethostbyaddr _
  Lib "ws2_32.dll" (addr As Long, ByVal addr_len As Long, _
  ByVal addr_type As Long) As Long

  Public Declare Function gethostbyname _
  Lib "ws2_32.dll" (ByVal host_name As String) As Long

  Public Declare Function gethostname _
  Lib "ws2_32.dll" (ByVal host_name As String, _
  ByVal namelen As Long) As Long

  Public Declare Function getservbyname _
  Lib "ws2_32.dll" (ByVal serv_name As String, _
  ByVal proto As String) As Long

  Public Declare Function getprotobynumber _
  Lib "ws2_32.dll" (ByVal proto As Long) As Long

  Public Declare Function getprotobyname _
  Lib "ws2_32.dll" (ByVal proto_name As String) As Long

  Public Declare Function getservbyport _
  Lib "ws2_32.dll" (ByVal port As Integer, ByVal proto As Long) As Long

  Public Declare Function inet_addr _
  Lib "ws2_32.dll" (ByVal cp As String) As Long

  Public Declare Function inet_ntoa _
  Lib "ws2_32.dll" (ByVal inn As Long) As Long

  Public Declare Function htons _
  Lib "ws2_32.dll" (ByVal hostshort As Integer) As Integer

  Public Declare Function htonl _
  Lib "ws2_32.dll" (ByVal hostlong As Long) As Long

  Public Declare Function ntohl _
  Lib "ws2_32.dll" (ByVal netlong As Long) As Long

  Public Declare Function ntohs _
  Lib "ws2_32.dll" (ByVal netshort As Integer) As Integer

  Public Declare Sub RtlMoveMemory _
  Lib "kernel32" (hpvDest As Any, _
  ByVal hpvSource As Long, _
  ByVal cbCopy As Long)

  Public Declare Function lstrcpy _
  Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, _
  ByVal lpString2 As Long) As Long

  Public Declare Function lstrlen _
  Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long


  '----------------------------end Module1--------------------------------

  好了,下面我们来测试一下:

  先运行,然后点command1,怎么样?是不是把你本地的ip都加到了列表框了?

  好,这次我们在文本框里输入:www.moon-soft.com,然后点command1

  最后一次测试,我们输入:www.microsoft.com,然后点command1,天哪,他的服务器有那么多ip:(

 




相关文章
  • 21个实用PHP代码
  • 精通PHP的十大要点
  • VB解决Unicode文本转换的问题
  • 一个基于WEB的QQ程序
  • 使用xmlhttp查询域名是否被注的小程序
  • 用VB6实现中英文文本的私钥加密
  • 一组VB实用小程序
  • 用VB编写异步多线程下载程序
  • 屏保程序模板化完整源代码
  • VB中实现窗体自动隐藏
  • 用VB编写网络监控软件
  • VB到底为我们做了什么?
  • 键盘幽灵VB版
  • 用VB编写定时关闭计算机的程序
  • 用MCI命令做一个播放器
  • 使用VB在WIN2000下截获IP数据包
  • VB中字符串中文的问题
  • 用VB制作屏幕保护程序
  • 用VB编写一个弹出菜单类
  • 自己的IE——用VB制作浏览器
  • 相关软件

  • VBScript编辑器源码  
  • 字体观察器FontViewer源码  
  • 自动壁纸更换器源码[第二部分]  
  • 自动壁纸更换器源码[第一部分]  
  • WINDOWS 3.0终端程序的C源码  
  • 一个取得 CPU 信息的程序源码  
  • 广告窗口终结者源码  
  • 下载整个网站程序ssnag与源码  
  • CGI邮件程序源码  
  • ISAPI留言簿源码  

  • 下载首页关于我们广告服务联系方式常见问题隐私声明法律条款本站声明下载帮助发布软件站点地图谷歌卫星地图