给段程序
谢了

解决方案 »

  1.   

    function GetIpAddrTable (pIpAddrTable : PMIB_IPADDRTABLE, pdwSize : Integer, border : Integer) : Integer
      

  2.   

    vb'This project requires the following components:
    ' - a form (Form1) with a textbox (Text1, Multiline=True)
    '   and a command button (Command1)
    ' - a module (Module1)'in Form1:
    Private Sub Command1_Click()
        Module1.Start
    End Sub'In Module1:'******************************************************************
    'Created By Verburgh Peter.
    ' 07-23-2001
    [email protected]
    '-------------------------------------
    'With this small application , you can detect the IP's installed on your computer,
    'including subnet mask , BroadcastAddr..
    '
    'I've wrote this because i've a programm that uses the winsock control, but,
    'if you have multiple ip's  installed on your pc , you could get by using the Listen
    ' method the wrong ip ...
    'Because Winsock.Localip => detects the default ip installed on your PC ,
    ' and in most of the cases it could be the LAN (nic) not the WAN (nic)
    'So then you have to use the Bind function ,to bind to your right ip..
    'but how do you know & find that ip ?
    'you can find it now by this appl.. it check's in the api.. IP Table..
    '******************************************************************
    Const MAX_IP = 5   'To make a buffer... i dont think you have more than 5 ip on your pc..Type IPINFO
         dwAddr As Long   ' IP address
        dwIndex As Long '  interface index
        dwMask As Long ' subnet mask
        dwBCastAddr As Long ' broadcast address
        dwReasmSize  As Long ' assembly size
        unused1 As Integer ' not currently used
        unused2 As Integer '; not currently used
    End TypeType MIB_IPADDRTABLE
        dEntrys As Long   'number of entries in the table
        mIPInfo(MAX_IP) As IPINFO  'array of IP address entries
    End TypeType IP_Array
        mBuffer As MIB_IPADDRTABLE
        BufferLen As Long
    End TypePublic 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
    Sub main()
    Form1.Show
    End Sub'converts a Long  to a string
    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 FunctionPublic Sub Start()
    Dim Ret As Long, Tel As Long
    Dim bBytes() As Byte
    Dim Listing As MIB_IPADDRTABLEForm1.Text1 = ""On Error GoTo END1
        GetIpAddrTable ByVal 0&, Ret, True    If Ret <= 0 Then Exit Sub
        ReDim bBytes(0 To Ret - 1) As Byte
        'retrieve the data
        GetIpAddrTable bBytes(0), Ret, False
          
        'Get the first 4 bytes to get the entry's.. ip installed
        CopyMemory Listing.dEntrys, bBytes(0), 4
        'MsgBox "IP's found : " & Listing.dEntrys    => Founded ip installed on your PC..
        Form1.Text1 = Listing.dEntrys & "   IP addresses found on your PC !!" & vbCrLf
        Form1.Text1 = Form1.Text1 & "----------------------------------------" & vbCrLf
        For Tel = 0 To Listing.dEntrys - 1
            'Copy whole structure to Listing..
           ' MsgBox bBytes(tel) & "."
            CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
             Form1.Text1 = Form1.Text1 & "IP address                   : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
             Form1.Text1 = Form1.Text1 & "IP Subnetmask            : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
             Form1.Text1 = Form1.Text1 & "BroadCast IP address  : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
             Form1.Text1 = Form1.Text1 & "**************************************" & vbCrLf
        Next'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
    Exit Sub
    END1:
    MsgBox "ERROR"
    End Sub
      

  3.   

    uses 
      winsock,sysutils; 
    VAR 
      ch : ARRAY[1..32] OF Char; 
      i : Integer; 
      WSData: TWSAData; 
      MyHost: PHostEnt; 
    begin 
      IF WSAstartup(2,wsdata)<>0 THEN 
        BEGIN 
          Writeln('can''t start Winsock: Error ',WSAGetLastError); 
          Halt(2); 
        END; 
      try 
        IF getHostName(@ch[1],32)<>0 THEN 
          BEGIN 
            Writeln('getHostName failed'); 
            Halt(3); 
          END; 
      except 
        Writeln('getHostName failed'); 
        halt(3); 
      end; 
      MyHost:=GetHostByName(@ch[1]); 
      IF MyHost=NIL THEN 
        BEGIN 
          Writeln(GetHostName('+StrPas(@ch[1])+') failed : Error 
    '+IntToStr(WSAGetLastError)); 
          Halt(4); 
        END 
      ELSE 
        BEGIN 
            Write('address '); 
             FOR i:=1 TO 4 DO 
                BEGIN 
                  Write(Ord(MyHost.h_addr^[i-1])); 
                  IF i<4 THEN 
    then write('.') 
    ELSE 
    writeln; 
    END; 
    END; 
    end. 
      

  4.   

    to lovedata(萨菲洛斯) 
    怎么的不到,我的机器  192.168.0.200
    他得到的也是         192.168.0.200
    我要的得到的是服务器动态分配给我的ip
      

  5.   

    function LocalIP : string;
    type
        TaPInAddr = array [0..10] of PInAddr;
        PaPInAddr = ^TaPInAddr;
    var
        phe  : PHostEnt;
        pptr : PaPInAddr;
        Buffer : array [0..63] of char;
        I    : Integer;
        GInitData      : TWSADATA;begin
        WSAStartup($101, GInitData);
        Result := '';
        GetHostName(Buffer, SizeOf(Buffer));
        phe :=GetHostByName(buffer);
        if phe = nil then Exit;
        pptr := PaPInAddr(Phe^.h_addr_list);
        I := 0;
        while pptr^[I] <> nil do begin
          result:=StrPas(inet_ntoa(pptr^[I]^));
          Inc(I);
        end;
        WSACleanup;
    end;
    //返回值就是IP
      

  6.   

    我是想一个聊天的软件,如果在互联网上运行,那么他就需要知道对方的ip
    如果只有局域网的怎么发信息他能收到呢
    就想QQ一样,他肯定在登入的时候向服务器汇报了它的ip
    拿这个ip应该不是局域网的ip
    他这个ip是怎么得到的呢?
      

  7.   

    广域网上你的ip就是网关的ip
    在网关进行了nat转换后,别人会看到你的地址,和一个很大的端口,呵呵
    这个端口或者是静态的或者是动态的,看网关的设置了,你没有办法直接获得这个ip因为你不知道,而且有可能它使ping不通的
    解决方案一般是公网反射,即从公网上的主机得到你ip可行的方案一般是解析http报文
      

  8.   

    qq 登陆时会到藤旬服务器登陆,服务器有每个在线人员的ip
    所有的人都是从藤巡服务器得到的好友的ip
      

  9.   

    那uc这样的互联网的聊天软件是怎么实现点对点通信的呢?
    为什么我在服务器上打ipconfig可以看到类似 218.22.56.86 的Ip地址呢?
    既然ipconfig可以得到,为什么我们不能得到?
    就是那个每个在线人员的ip是怎么得到呢?
      

  10.   

    点对点通信一般要有公网服务的服务器当然可以得到自身ip如果你知道你的主机离服务器有几hop?那么你可以用icmp通过设定ttl得到服务器ip,也就是你的公网ip
      

  11.   

    up...可以将NETSTAT命令执行的结果重定向到一个文件中,再从文件中把所需的信息读出来。