有两个问题  一个50分
一。哪位高手知道如何用vb 获取外网ip及所在的物理地址 我急用 不胜感激 把代码弄上来啊  可用给全分二。哪位高手知道怎么在richtextbox中添加图片 及改变部分字体的颜色   把代码弄上来  可用给全分

解决方案 »

  1.   

    先来个获取网卡物理地址的:
    Option ExplicitPublic Const NCBASTAT As Long = &H33
    Public Const NCBNAMSZ As Long = 16
    Public Const HEAP_ZERO_MEMORY As Long = &H8
    Public Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
    Public Const NCBRESET As Long = &H32Public Type NET_CONTROL_BLOCK
        ncb_command As Byte
        ncb_retcode As Byte
        ncb_lsn As Byte
        ncb_num As Byte
        ncb_buffer As Long
        ncb_length As Integer
        ncb_callname As String * NCBNAMSZ
        ncb_name As String * NCBNAMSZ
        ncb_rto As Byte
        ncb_sto As Byte
        ncb_post As Long
        ncb_lana_num As Byte
        ncb_cmd_cplt As Byte
        ncb_reserve(9) As Byte
        ncb_event As Long
    End TypePublic Type ADAPTER_STATUS
        adapter_address(5) As Byte
        rev_major As Byte
        reserved0 As Byte
        adapter_type As Byte
        rev_minor As Byte
        duration As Integer
        frmr_recv As Integer
        frmr_xmit As Integer
        iframe_recv_err As Integer
        xmit_aborts As Integer
        xmit_success As Long
        recv_success As Long
        iframe_xmit_err As Integer
        recv_buff_unavail As Integer
        t1_timeouts As Integer
        ti_timeouts As Integer
        Reserved1 As Long
        free_ncbs As Integer
        max_cfg_ncbs As Integer
        max_ncbs As Integer
        xmit_buf_unavail As Integer
        max_dgram_size As Integer
        pending_sess As Integer
        max_cfg_sess As Integer
        max_sess As Integer
        max_sess_pkt_size As Integer
        name_count As Integer
    End Type
    Public Type NAME_BUFFER
        name As String * NCBNAMSZ
        name_num As Integer
        name_flags As Integer
    End TypePublic Type ASTAT
        adapt As ADAPTER_STATUS
        NameBuff(30) As NAME_BUFFER
    End TypePublic Declare Function Netbios Lib "netapi32.dll" (pncb As NET_CONTROL_BLOCK) As BytePublic Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)Public Declare Function GetProcessHeap Lib "kernel32" () As Long
    Public Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As LongPublic Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
    Public Function GetMACAddress() As String    Dim tmp As String
        Dim pASTAT As Long
        Dim NCB As NET_CONTROL_BLOCK
        Dim AST As ASTAT
        
        NCB.ncb_command = NCBRESET
        Call Netbios(NCB)
        
        NCB.ncb_callname = "* "
        NCB.ncb_command = NCBASTAT
        
        NCB.ncb_lana_num = 0
        NCB.ncb_length = Len(AST)
        
        pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _
        Or HEAP_ZERO_MEMORY, NCB.ncb_length)
        
        If pASTAT = 0 Then
            Debug.Print "memory allocation failed!"
            Exit Function
        End If
        
        NCB.ncb_buffer = pASTAT
        Call Netbios(NCB)
        
        CopyMemory AST, NCB.ncb_buffer, Len(AST)
        
        tmp = Format$(Hex(AST.adapt.adapter_address(0)), "00") & " " & _
        Format$(Hex(AST.adapt.adapter_address(1)), "00") & " " & _
        Format$(Hex(AST.adapt.adapter_address(2)), "00") & " " & _
        Format$(Hex(AST.adapt.adapter_address(3)), "00") & " " & _
        Format$(Hex(AST.adapt.adapter_address(4)), "00") & " " & _
        Format$(Hex(AST.adapt.adapter_address(5)), "00")
        
        HeapFree GetProcessHeap(), 0, pASTAT
        
        GetMACAddress = tmpEnd Function
      

  2.   

    一,获得外网可以直接用 WebBrowser1
    把这句放到事件里可以了.
    WebBrowser1.Navigate "http://www.ip138.com/ip2city.asp"二,
    我没用richtextbox,不知道了。
      

  3.   

    上面那个的用法如下:
    private sub command1_click()
        msgbox "网卡物理地址是" & GetMACAddress()
    end sub下面再来个获取外网IP地址的,这个需要添加inet控件,然后通过访问一个网页来分析返回值:
    txtIP显示外网IP地址,txtAddress显示所在地Private Sub Command1_Click()
        Inet1.Execute "http://www.abcbit.com/ip.php" '从指定网址获取返回信息
    End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer) ' 分析返回信息得到公网IP和地理位置
        Dim s0 As String, s As String, sTime As String
        Dim a0 As Integer, a1 As Integer, a2 As Integer
        Dim b0 As Integer, b1 As Integer, b2 As Integer
        Dim sIP As String, sAddress As String
        Debug.Print State
        On Error GoTo goter
        Select Case State
            Case 11
                txtIP.Text = "未知"
                txtAddress.Text = "未知"
                Exit Sub
            Case 12
                s0 = ""
                s = Inet1.GetChunk(1024)
                Do While s <> ""
                    s0 = s0 + s
                    s = Inet1.GetChunk(1024)
                Loop
                If InStr(1, s0, "您的IP地址:") = 0 Then
                    txtIP.Text = "未知"
                    txtAddress.Text = "未知"
                    Exit Sub
                End If
                a0 = InStr(1, s0, "您的IP地址:")
                a1 = InStr(a0 + 8, s0, "<strong>", vbTextCompare) + 8
                a2 = InStr(a1, s0, "</strong>")
                sIP = Mid(s0, a1, a2 - a1)
                If Not (sIP Like "*.*.*.*") Then GoTo goter
                b0 = InStr(1, s0, "IP所在位置:")
                b1 = InStr(b0 + 8, s0, "#F0F0F0", vbTextCompare) + 11
                b2 = InStr(b1, s0, "</td>")
                sAddress = Mid(s0, b1, b2 - b1)
                txtIP.Text = sIP
                txtAddress.Text = sAddress
                Exit Sub
        End Select
        Exit Sub
    goter:
        txtIP.Text = "未知"
        txtAddress.Text = "未知"
    End Sub
      

  4.   

    再来段richtextbox中改变字体的代码:Private Sub Command1_Click()
        RichTextBox1.SelStart = 3 '要改变字体的起始字符
        RichTextBox1.SelLength = 2 '要改变字体的字符长度
        RichTextBox1.SelColor = vbRed '所选字体改为红色
        RichTextBox1.SelBold = True '所选字体改为加粗
    End Sub
      

  5.   

    在RichTextBox中插入图片 
    Private Sub Command1_Click()
    RichTextBox1.OLEObjects.Add , , "c:\1.bmp"
    End Sub
      

  6.   

    6楼  感谢  那要加gif图片怎么办呢
      

  7.   

    网站一般不会关闭.你自己写个ASP页不就行了.