vb.net读取网口信息,vb网口通信
VB.NET 获取网关IP MAC地址
我找了一些C# 的VB。NET 貌似很少不过都是。NET 平台。你看看吧都应该通用的。
网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了会同免费建站欢迎大家使用!
添加对System.Management的引用
using System.Management;
。。。
//获取IP,子网掩码(subnet mask)和默认网关
ManagementClass mc = new ManagementClass( "Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection nics = mc.GetInstances();
foreach(ManagementObject nic in nics)
{
if(Convert.ToBoolean(nic[ "ipEnabled "]) == true)
{
Console.WriteLine((nic[ "IPAddress "] as String[])[0]);
Console.WriteLine((nic[ "IPSubnet "] as String[])[0]);
Console.WriteLine((nic[ "DefaultIPGateway "] as String[])[0]);
}
}
获取硬件信息源代码:
获取硬件信息演示程序:
汉化
利用using System.Management类来获取相应的硬件知识
其实这类东西很容易找到答案的,方法非常多,最常见的API模式,你去搜索吧,保证一把一把的
vb.net 怎么用事件触发的方式读取串口数据
首先:
textbox里没有显示,是因为SerialPort1和TextBox2不是同一线程创建的,需要跨线程操作。需要用到委托,这样才能显示出来。
其次:
我觉得用串口的接收数据事件更好一些。
下面代码供参考:
'----------------------
'串口接收数据事件,其实比用定时器更好,
'触发事件的条件可以自己在form_load中设置ReceivedBytesThreshold属性数值,默认为ReceivedBytesThreshold=1
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim strRecvData As String = ""
strRecvData = SerialPort1.ReadExisting
Call disPlayComData(strRecvData)
End Sub
Delegate Sub callback(ByVal strT As String) '定义委托
Sub showString(ByVal comdata As String) '显示结果
Me.TextBox1.Text = "结果:" comdata
End Sub
Sub disPlayComData(ByVal strTmp As String) '判定是否为跨线程
If Me.TextBox1.InvokeRequired Then
Dim d As New callback(AddressOf showString)
Me.Invoke(d, New Object() {strTmp})
Else
Me.TextBox1.Text = strTmp
End If
End Sub
VB.NET 如何获取网页中的数据
Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
'启动一次具体的数据采集工作,返回采集到的HTML内容:要求必须输入带://的全地址数据
On Error Resume Next
Dim Str_WebContent As String = "请输入查找网站地址."
Dim wb As WebClient = New WebClient() '//创建一个WebClient实例
If mWebsiteUrl.IndexOf("://") 0 Then
'//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。(可有可无)
wb.Credentials = CredentialCache.DefaultCredentials
'//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)
'//转换字符
If mWebsiteType Then
Str_WebContent = Encoding.Default.GetString(pagedata)
Else
Str_WebContent = Encoding.UTF8.GetString(pagedata)
End If
End If
Return Str_WebContent '提取出来新闻内容,删除Body前后的多余内容,同时补充上该 Body标记,形成完整的内容 Str_WebContent '
End Function
求VB.NET读取网页内容写法
Imports System.Net
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim stream As IO.Stream = WebRequest.Create(UrlAdress).GetResponse().GetResponseStream()
'注意urladress为你上面的网页地址。
Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8)
Label1.Text = Regex.Match(sr.ReadToEnd, "回答采纳率").ToString
'sr。readtoend读取网页流到末尾,即使用正则表达式从网页流中提取“回答采纳率”,赋值给Label1.Text ‘没有则为空
sr.Dispose() '关闭流
End Sub'要提取什么东西用正则表达式最好
End Class
电脑有两张网卡。如何用vb.net分别获取网卡的IP?求大神明路!
'要使得引用System.Management有效,先通过菜单
'[项目]--[添加引用],在“.Net”选项卡里,选择“System.Management”,单击[确定]
Imports System.Management
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MySearcher As New ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
For Each MySearcherObj As ManagementObject In MySearcher.Get
If CBool(MySearcherObj("IPEnabled")) Then
MsgBox(MySearcherObj("IPAddress")(0))
End If
Next
End Sub
End Class
网站题目:vb.net读取网口信息,vb网口通信
浏览路径:http://cdiso.cn/article/dsgjgdd.html