Private Sub Form_Load()
公司主營業(yè)務(wù):網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出黎平免費(fèi)做網(wǎng)站回饋大家。
Debug.Print ChangeIP("192.168.1.200", "255.255.255.0", "", "", "")
End Sub Public Function ChangeIP(IP As String, NM As String, GW As String, MDNS As String, SDNS As String) As String
'返回值說明:返回一個(gè)設(shè)置的中文說明.
Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" strComputer "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(IP) 'ip地址
strSubnetMask = Array(NM) '子網(wǎng)掩碼
strGateway = Array(GW) '網(wǎng)關(guān)
strDNS = Array(MDNS, SDNS) '主DNS各備DNS
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
ChangeIP = "設(shè)置成功"
Else
If errEnable = 0 Then
ChangeIP = "IP地址和子網(wǎng)掩碼設(shè)置成功, "
Else
ChangeIP = "IP地址或子網(wǎng)掩碼設(shè)置失敗, "
End If
If errGateways = 0 Then
ChangeIP = ChangeIP "默認(rèn)網(wǎng)關(guān)設(shè)置成功, "
Else
ChangeIP = ChangeIP "默認(rèn)網(wǎng)關(guān)設(shè)置失敗, "
End If
If errDNS = 0 Then
ChangeIP = ChangeIP "DNS設(shè)置成功"
Else
ChangeIP = ChangeIP "DNS設(shè)置失敗"
End If
End If
NextEnd Function
1.獲取當(dāng)前電腦名:System.Net.Dns.GetHostName()
2.根據(jù)電腦名取出全部IP地址:System.Net.Dns.Resolve(電腦名).AddressList
或者 System.Net.Dns.GetHostByName(電腦名).AddressList
3.根據(jù)IP地址取出電腦名:System.Net.Dns.Resolve(IP地址).HostName
Dim th As Threading.Thread
2 Dim tcpl As System.Net.Sockets.TcpListener
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6 th.Start()
7 End Sub
8
9 Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10 Try
11 If IP "" Then
12 Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13 Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14 Dim reqStream As New IO.StreamWriter(tcpStream)
15 reqStream.Write(SendMsg)
16 reqStream.Flush()
17 tcpStream.Close()
18 tcpc.Close()
19 End If
20 Catch ex As Exception
21 MsgBox(ex.Message.ToString)
22 End Try
23 End Sub
24 Private Sub MyListen()Sub MyListen()
25 Try
26 Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27 tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28 tcpl.Start()
29 While True
30 Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31 Dim MyBuffer(1024) As Byte
32 Dim i As Integer
33 i = s.Receive(MyBuffer)
34 If i 0 Then
35 Dim lstrRec As String
36 Dim j As Integer
37 For j = 0 To i - 1
38 TextBox1.Text += Chr(MyBuffer(j)) ","
39 Next
40 End If
41 End While
42 Catch ex As Exception
43 MsgBox(ex.Message.ToString)
44 End Try
45 End Sub
46
47 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48 SendMessage("192.168.0.61", TextBox2.Text)
49 End Sub
需要出口設(shè)備進(jìn)行映射內(nèi)部地址;或使用打洞技術(shù)穿透NAT,但使用TCP打洞非常困難。
參考
穿透NAT是非常困難的,因?yàn)镹AT的過程中在出口路由器上的Port已經(jīng)不是你定義的iPort了,具體是多少也不固定
做exe程序獲取本機(jī)IP地址用
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList
做web程序獲取客戶端的IP地址用
HttpContext.Current.Request.ServerVariables("REMOTE_ADDR"])
建議你使用注冊表的API進(jìn)行修改
封裝兩個(gè)NET函數(shù)給你
private?string?GetReg(string?RegPath)??取得注冊表項(xiàng)內(nèi)容
{
string?str="";
RegistryKey?hkml?=?Registry.LocalMachine;?
RegistryKey?software?=?hkml.OpenSubKey("SOFTWARE",true);?
RegistryKey?aimdir?=?software.OpenSubKey("krabs",true);
if?(aimdir?!=?null)
{
if?(aimdir.GetValue(RegPath)?!=?null)
str?=?aimdir.GetValue(RegPath).ToString();
if?(str?!=?null)
return?str;
return?null;
}
return?null;
}
private?bool?SetReg(string?RegPath,string?Data)??//設(shè)置注冊表內(nèi)容
{
RegistryKey?reg?=?Registry.LocalMachine;
RegistryKey?software?=?reg.OpenSubKey("SOFTWARE",?true);
RegistryKey?aimdir1?=?software.CreateSubKey("krabs");
if?(aimdir1?==?null)
return?false;
aimdir1.SetValue(RegPath,?Data);
return?true;
}
分享文章:vb.net設(shè)置ip,Vb Net
網(wǎng)站鏈接:http://vcdvsql.cn/article0/hecoio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、軟件開發(fā)、微信公眾號、品牌網(wǎng)站建設(shè)、云服務(wù)器、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)