设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2118|回复: 3
打印 上一主题 下一主题

如何获得本机器的IP地址?

[复制链接]
跳转到指定楼层
1#
发表于 2006-11-13 05:27:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
各位高手:

本人在编写EXCEL分析SYBASE数据时,遇到想通过确认本机的IP地址来设定分析表的使用范围,必须是动态识别IP地址,请高手帮忙,谢谢!有其他手段获得IP,然后传给EXCEL的办法也行。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-11-14 17:45:00 | 只看该作者
试试下面的代码网上的)

Option Explicit

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
   
  Const Max_IP = 5
  
  Type IPINFO
      dwAddr   As Long
      dwIndex   As Long
      dwMask   As Long
      dwBCastAddr   As Long
      dwReasmSize     As Long
      UnUsed1   As Integer
      UnUsed2   As Integer
  End Type
   
  Type MIB_IPADDRTABLE
      dEntrys   As Long
      mIPInfo(Max_IP)   As IPINFO
  End Type
   
  Type IP_Array
      mBuffer   As MIB_IPADDRTABLE
      BufferLen   As Long
  End Type

   
  Public Function ConvertAddressToString(longAddr As Long) As String
      Dim MyByte(3)     As Byte
      Dim Cnt     As Long
      CopyMemory MyByte(0), longAddr, 4
      For Cnt = 0 To 3
          ConvertAddressToString = ConvertAddressToString + CStr(MyByte(Cnt)) + "."
      Next Cnt
      ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
  End Function
   
  Public Sub MsgIPAddr()
      Dim Ret     As Long, Tel       As Long
      Dim bBytes() As Byte
      Dim Listing  As MIB_IPADDRTABLE
      On Error GoTo End1
      GetIpAddrTable ByVal 0&, Ret, True
      If Ret <= 0 Then Exit Sub
      ReDim bBytes(0 To Ret - 1) As Byte
      GetIpAddrTable bBytes(0), Ret, False
      CopyMemory Listing.dEntrys, bBytes(0), 4
      MsgBox "找到 " & Listing.dEntrys & "   个IP Address!"
      For Tel = 0 To Listing.dEntrys - 1
          CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))                        
          MsgBox "IP Address:" & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)
      Next
      End
End1:
      MsgBox Err.Number & Err.Description
      End
  End Sub

3#
 楼主| 发表于 2006-11-16 05:58:00 | 只看该作者
十分感谢!以后请多多赐教。
4#
发表于 2006-11-17 01:43:00 | 只看该作者
呵,别客气,赐教不敢当,一起交流探讨吧.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-5 19:38 , Processed in 0.107285 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表