正在阅读:.net中取得本机IP地址的方法两则.net中取得本机IP地址的方法两则

2004-08-19 10:03 出处:CSDN 作者:tanaya 责任编辑:linjixiong


  Private Function GetIPAddress() As String
  On Error GoTo Z
  Dim wsa As WSAData
  Dim rVal As Long
  Dim sHost As String * 256
  Dim lp As Long
  Dim lpa As Long
  Dim IpAdr(0 To 3) As Byte
  rVal = WSAStartup((2 + &H100), wsa)
  If rVal = 0 Then
  gethostname sHost, 256
  lp = gethostbyname(sHost)
  If lp Then
  CopyMemoryIP lpa, lp + 16, 4
  CopyMemoryIP IpAdr(0), lpa, 4
  GetIPAddress = CStr(IpAdr(0)) & "." & CStr(IpAdr(1)) & "." & CStr(IpAdr(2)) & "." & CStr(IpAdr(3))
  End If
  WSACleanup
  End If
  Exit Function
  Z:
  GetIPAddress = ""
  End Function

  Private Sub Command1_Click()
  Dim ret As String
  ret = GetIPAddress
  If ret <> "" Then
  MsgBox "当前计算机网卡IP:" & ret
  End If
  End Sub

  '----------------------------
  ' 作者:唐细刚
  ' 邮箱:tanaya@163.com
  '----------------------------
  


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品