shell "ipconfig /all >c:\ipconfig.txt",vbHide
'然后读文件c:\ipconfig.txt的内容

解决方案 »

  1.   

    我现在用的。需要Winsock'*************************************************************
    '取本机MAC地址
    Private Function GetRemoteMACAddress(ByVal sRemoteIP As String, sRemoteMacAddress As String) As Boolean
        Dim dwRemoteIP   As Long
        Dim pMacAddr   As Long
        Dim bpMacAddr()   As Byte
        Dim PhyAddrLen   As Long
        Dim cnt   As Long
        Dim tmp   As String
        dwRemoteIP = inet_addr(sRemoteIP)
        If dwRemoteIP <> 0 Then
             PhyAddrLen = 6
             If SendARP(dwRemoteIP, 0&, pMacAddr, PhyAddrLen) = NO_ERROR Then
                 If pMacAddr <> 0 And PhyAddrLen <> 0 Then
                      ReDim bpMacAddr(0 To PhyAddrLen - 1)
                      CopyMemory bpMacAddr(0), pMacAddr, ByVal PhyAddrLen
                      For cnt = 0 To PhyAddrLen - 1
                          If bpMacAddr(cnt) = 0 Then
                            tmp = tmp & "00-"
                          Else
                           tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"
                          End If
                      Next
                     If Len(tmp) > 0 Then
                           sRemoteMacAddress = Left$(tmp, Len(tmp) - 1)
                           GetRemoteMACAddress = True
                      End If
                      Exit Function
                    Else
                        GetRemoteMACAddress = False
                    End If
              Else
               GetRemoteMACAddress = False
              End If
           Else
             GetRemoteMACAddress = False
        End If
    End Function用法:
    Dim sRemoteMacAddress   As String
    Call GetRemoteMACAddress(Winsock1.LocalIP, sRemoteMacAddress)
    获取IP:MsgBox "本机IP:" & Winsock1.LocalIP 
    获取计算机名:Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Sub Command2_Click()
    Dim PcNm As String * 255
    If GetComputerName(PcNm, 255&) <> 0 Then
    Print PcNm
    End If
    End Sub
      

  2.   

    使用这个运行ipconfig /all
    http://download.csdn.net/source/3057332
      

  3.   

    http://download.csdn.net/source/3057332
      

  4.   

    执行了这命令不报错,也没产生文件,为什么?
    我在dos窗口下直接ipconfig /all >c:\ipconfig.txt能产生文件
    为什么?
      

  5.   

    看看这个
    http://hi.baidu.com/cbm666/blog/item/668d09232507d34a93580755.html
      

  6.   

    关于MAC地址,请参考:http://www.m5home.com/blog/article.asp?id=510关于本机IP,猜你想得到的是对外IP.这要考虑很多情况.如果目标机器是在局域网中通过网关而不是直接拨号上网,要获取就得通过外部服务器.简单点,访问:http://www.ip138.com/再对"您的IP地址是:[XXXXXXXXX]"做个处理就可以了.
      

  7.   

    计算机名直接调用getcomputername.
      

  8.   

    想得到的只是局域网IP,不是对外的,就是局域网的如192.168.1.37,都是固定IP
      

  9.   

    那就生成一个批处理文件比如c:\ipall.bat内容为
    ipconfig /all >c:\ipconfig.txt
    然后
    shell "c:\ipall.bat",vbHide
      

  10.   

    其实用shell是最方便的一个方法,但关键的问题是上面的写法没对,
    你用这个吧!
    Shell "cmd   /c   ipconfig   /all   > " & Chr(34) & "c:\ip.txt " & Chr(34), vbHide
    运行后可以在c盘根下生成一个ip.txt文件的!
    vb6测试通过!
      

  11.   

    那这个调用GetIpAddrTable就可以得到,我写个封装吧.
      

  12.   

    参考:取得本机IP地址列表(VB6.0代码)
      

  13.   

    For cnt = 0 To PhyAddrLen - 1                       If bpMacAddr(cnt) = 0 Then                        tmp = tmp & "00-"                      Else                       tmp = tmp & Hex$(bpMacAddr(cnt)) & "-"                      End If                  Next
    90-FB-A6-8-81-39 前面有0就不对了.