检测我的 adsl 是否连上网了,连上了的话,取得ip地址。再将此IP地址告诉我的朋友,让他们来访问我的计算机。我想要的是用程序来做。

解决方案 »

  1.   

    用Winsock连一下www.sina.com.cn,成功后读Winsock.LocalIP
      

  2.   

    ip真的很难得到,如果你有asp,php空间,那你的ip地址还是可以通过http;//www.**.com/*.php(*.asp)来获得,有其他方法告知我,我也正在找
      

  3.   

    '别忘了给分呀
    '在窗体上加一个按钮控件Command1就可以了
    Private Const MAX_IP = 255
    '王子编程俱乐部 http://www.15518.com
        Private 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
        Private Type MIB_IPADDRTABLE
         dEntrys As Long
         mIPInfo(MAX_IP) As IPINFO
        End Type
        Private Type IP_Array
         mBuffer As MIB_IPADDRTABLE
         BufferLen As Long
        End Type
        Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
        Private Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
        Dim strIP As String '所有ip
        Dim webip As String '面向互联网ip
    Private Sub Command1_Click()
         checkip
         MsgBox strIP & vbCrLf
         MsgBox "本机对外ip:" & webip
    End Sub
         
        Private 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 checkip()
         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
         strIP = "你机子上有 " & Listing.dEntrys & " 个 IP 地址。" & vbCrLf
         strIP = strIP & "------------------------------------------------" & vbCrLf & vbCrLf
         For Tel = 0 To Listing.dEntrys - 1
         CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
         strIP = strIP & "IP 地址 : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
         strIP = strIP & "子网掩码 : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
         strIP = strIP & "广播地址 : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
         strIP = strIP & "------------------------------------------------" & vbCrLf
         Dim thisip As String, ipqz As String
         thisip = ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)
         ipqz = Left(thisip, InStr(thisip, ".") - 1)
         If ipqz <> "10" And ipqz <> "172" And ipqz <> "192" And ipqz <> "127" Then
         webip = thisip
         End If
         Next
         Exit Sub
    END1:
         MsgBox "ERROR"
        End Sub
      

  4.   

    还有一种方式,找一个可以显示IP的网站,定时访问,把你的IP取出来!
    http://expert.csdn.net/Expert/topic/1835/1835213.xml?temp=.6877405
      

  5.   

    建议用希网的免费动态网络域名来做,这个是全免费的,还有个二级域名,我一直在用,感觉不错哦。。   http://www.3322.org/
    看看我自己的服务器吧。。 http://drgame.126.com  IIS做的,不要黑我哦。。:),不用什么IP,希网的动态域名会随时为你更新IP的。你只要给你的朋友你的域名就可以了。。
      

  6.   

    xiaoyao961(逍遥浪子)的找Internet IP的方法不错。 我说说检查是否连上internet的方法:使用ping函数(用API自定义),PING一个有名的允许ping的网址,判断返回数据(看能否ping通)即可。
      

  7.   

    有看头,把代码COPY回家试试先!