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

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

  方法1:(控件法)

  新建工程,在工程中加入Winsock控件和一个按钮控件

  代码:



  Option Explicit

  Private Sub Command1_Click()
  MsgBox "当前计算机网卡IP:" & Winsock1.LocalIP
  End Sub

  方法2:(API法)

  新建工程,在工程中加入一个按钮控件

  代码:


  Option Explicit

  Private Type WSAData
  wVersion As Integer
  wHighVersion As Integer
  szDescription(0 To 256)
  szSystemStatus(0 To 128)
  wMaxSockets As Integer
  dwVendorInfo As Long
  End Type

  Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSAData As WSAData) As Long
  Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
  Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal szHost As String, ByVal dwHostLen As Long) As Long
  Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal szHost As String) As Long
  Private Declare Sub CopyMemoryIP Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

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