大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
在菜单中的【工程】—【引用】下,添加“Microsoft WMI Scripting V1.1 Library”,然后在Form1窗体上添加1个Combo1、Text1(0)、Text1(1)、Text1(2)、Text1(3)和Command1、Command2,代码如下:
成都创新互联是专业的网站建设公司,提供网站建设,网站制作,网站设计等网站开发一体化解决方案;包括H5网站设计,小程序设计,网站定制,企业网站建设,购物商城网站建设,成都响应式网站建设公司,建网站,PHP网站建设,软件开发,软文发布平台,网站营销。欢迎做网站的企业前来合作洽谈,成都创新互联将竭诚为您服务!
Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
'Text1(0)为IP地址、Text1(1)为子网掩码、Text1(2)为缺省网关、Text1(3)为DNS
Private Sub Form_Load()
Set objSWbemServices = GetObject("winmgmts:")
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objSWbemObject In objSWbemObjectSet
Combo1.AddItem objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡
Next
Combo1.Text = Combo1.List(0)
Combo1.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objSWbemServices = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemObject = Nothing
End Sub
'当选择了网卡后,显示当前所选网卡的设置
Private Sub Combo1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" Combo1.Text "'")
For Each objSWbemObject In objSWbemObjectSet
If objSWbemObject.DHCPEnabled Then
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
If IsNull(objSWbemObject.DNSServerSearchOrder) Then
Text1(3).Text = ""
Else
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Else
Text1(0).Text = objSWbemObject.IPAddress(0)
Text1(1).Text = objSWbemObject.IPSubnet(0)
Text1(2).Text = objSWbemObject.DefaultIPGateway(0)
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Next
End Sub
'设置网卡的IP地址、子网掩码、缺省网关和DNS
Private Sub Command1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" Combo1.Text "'")
For Each objSWbemObject In objSWbemObjectSet
objSWbemObject.EnableStatic Array(Text1(0).Text), Array(Text1(1).Text)
objSWbemObject.SetGateways Array(Text1(2).Text)
objSWbemObject.SetDNSServerSearchOrder Array(Text1(3).Text)
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function EnumNetworkAdapters() As String
Try
Dim query As System.Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
Dim queryCollection As System.Management.ManagementObjectCollection = query.Get()
Dim mo As New System.Management.ManagementObject
For Each mo In queryCollection
If IsDBNull(mo.Item("Description")) = False Then
EnumNetworkAdapters = mo.Item("Description") "|||"
End If
If IsDBNull(mo.Item("macaddress")) = False Then
If mo.Item("macaddress") "" Then
EnumNetworkAdapters = mo.Item("macaddress") "|||"
End If
End If
If IsDBNull(mo.Item("IPAddress")) = False Then
Dim temp As String
temp = Join(mo.Item("IPAddress"), ".")
If temp "" Then
EnumNetworkAdapters = temp "|||"
End If
End If
Next
Catch err AS Exception
EnumNetworkAdapters = err.Message err.StackTrace
End Try
End Function
如电脑使用Win7系统,可按以下方法设置DNS:您右键点击电脑桌面的“网络”图标 ,选择“属性” >选择“控制面板” >在“网络和共享中心”中可看到当前的网络状况,点击左边的“更改适配器设置” >右键单击“本地连接”,选择“属性” >选择“internet协议版本4(TCP/IPv4)”,点击“属性” >选择“使用下列DNS服务器地址”,输入“首选”及“备用”DNS地址,最后点击“确认”即可。
温馨提示:每个地市的DNS地址参数不同,建议您可联系人工客服或前往营业厅进行咨询了解。
做exe程序获取本机IP地址用
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList
做web程序获取客户端的IP地址用
HttpContext.Current.Request.ServerVariables("REMOTE_ADDR"])
设置方法:
1.点击电脑左下角“开始”,接着点击开始界面右栏出现的“控制面板”
2.在控制面板界面点击选择“网络和internet”。
3.接着点击选择“网络和共享中心”。
4.在新的界面点击选择左侧的“更改适配器设置”。
5.找到无线网络连接后,鼠标右键单击选择“属性”。
6.在属性界面的“网络”选项卡内勾选“internet协议版本4”,接着继续点击右下角的“属性”。
7.在“常规”选项卡内勾选“自动获得IP地址”与“自动获得DNS服务器地址”,或者自行设置地址,然后点击”确定”即可。