一般机子上面有网卡的名称都是
本地连接
如果有多块网卡
就是
本地连接2
本地连接3
英文系统上就是
local connection,local connection 2.....
但是改名了之后就不是这个名称了
我想问一下怎么获取这个IP的名称....
以及怎么获取绑定在某一个网卡上的IP.谢谢了.
本地连接
如果有多块网卡
就是
本地连接2
本地连接3
英文系统上就是
local connection,local connection 2.....
但是改名了之后就不是这个名称了
我想问一下怎么获取这个IP的名称....
以及怎么获取绑定在某一个网卡上的IP.谢谢了.
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2
:AccName2
set AccessName=%AccessName:~0,-2%
echo %AccessName%>ip.txt
然后用VB读取文件即可还有就是使用API和读取注册表来实现Option ExplicitPrivate Const ERROR_SUCCESS As Long = 0
Private Const MAX_ADAPTER_NAME_LENGTH As Long = 256
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Long = 128
Private Const MAX_ADAPTER_ADDRESS_LENGTH As Long = 8Private Const MIB_IF_TYPE_ETHERNET As Long = 6Private Type IP_ADDRESS_STRING
IpAddr(0 To 15) As Byte
End TypePrivate Type IP_MASK_STRING '子网掩码
IpMask(0 To 15) As Byte
End TypePrivate Type IP_ADDR_STRING
dwNext As Long
IpAddress As IP_ADDRESS_STRING
IpMask As IP_MASK_STRING
dwContext As Long
End TypePrivate Type IP_ADAPTER_INFO
dwNext As Long
ComboIndex As Long 'reserved
sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3)) As Byte
sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte
dwAddressLength As Long
sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1)) As Byte
dwIndex As Long
uType As Long
uDhcpEnabled As Long
CurrentIpAddress As Long
IpAddressList As IP_ADDR_STRING
GatewayList As IP_ADDR_STRING
DhcpServer As IP_ADDR_STRING
bHaveWins As Long
PrimaryWinsServer As IP_ADDR_STRING
SecondaryWinsServer As IP_ADDR_STRING
LeaseObtained As Long
LeaseExpires As Long
End TypePrivate Declare Function GetAdaptersInfo Lib "iphlpapi.dll" _
(pTcpTable As Any, _
pdwSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long
Private Adapter As IP_ADAPTER_INFOPublic Function LocalIPAdapterName() ' As String '添加适配器名称
Dim a() As Byte, Str As String
Dim cbRequired As Long
Dim buff() As Byte
Dim ptr1 As Long
Dim AdapterName As String
Call GetAdaptersInfo(ByVal 0&, cbRequired)
If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte
If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then
'get a pointer to the data stored in buff()
ptr1 = VarPtr(buff(0)) Do While (ptr1 <> 0)
'copy the data from the pointer to the
'first adapter into the IP_ADAPTER_INFO type
CopyMemory Adapter, ByVal ptr1, LenB(Adapter)
With Adapter
'获取IP地址
AdapterName = TrimNull(StrConv(.sAdapterName, vbUnicode))
AdapterName = GetKeyValue(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" & AdapterName & "\Connection", "Name", 1)
AdapterName = Replace(AdapterName, Chr(0), "")
'If Len(AdapterName) > 0 Then Exit Do
If AdapterName <> "" Then Frm_SetIP.Combo_IP.AddItem AdapterName
'这时的AdapterName 是你需要的答案如果有多网卡就有几个这样的值
ptr1 = .dwNext
End With 'With Adapter
'ptr1 is 0 when (no more adapters)
Loop 'Do While (ptr1 <> 0) End If 'If GetAdaptersInfo
End If 'If cbRequired > 0 'return any string found
'LocalIPAdapterName = AdapterName
End Function
for /f "skip=3 tokens=2*" %%a in ('ipconfig') do set AccessName=%%b&& goto AccName2
:AccName2
set AccessName=%AccessName:~0,-2%
echo %AccessName%>ip.txt能把详细点的方法告诉我吗?谢谢先.
getkeyvalue取到的值是false
chenhui530解答下可以么?
Dim nul As Long
nul = InStr(StrIn, vbNullChar)
Select Case nul
Case Is > 1
TrimNull = Left(StrIn, nul - 1)
Case 1
TrimNull = ""
Case 0
TrimNull = Trim(StrIn)
End Select
End Function补上