forked from basildane/WakeOnLAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcSubnet.vb
67 lines (54 loc) · 2.54 KB
/
CalcSubnet.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
' WakeOnLAN - Wake On LAN
' Copyright (C) 2004-2019 Aquila Technology, LLC. <[email protected]>
'
' This file is part of WakeOnLAN.
'
' WakeOnLAN is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' WakeOnLAN is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with WakeOnLAN. If not, see <http://www.gnu.org/licenses/>.
Imports System.Net
Public Class CalcSubnet
Dim _properties As Properties
Private Sub CalcSubnet_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_properties = Owner
IpIP.Text = _properties.IP.Text
IpBroadcast.Text = ""
IpSubnet.Text = IPAddress.Broadcast.ToString()
End Sub
Private Function GetBroadcastAddress(address As IPAddress, subnetMask As IPAddress) As IPAddress
Dim ipAdressBytes As Byte() = address.GetAddressBytes()
Dim subnetMaskBytes As Byte() = subnetMask.GetAddressBytes()
If ipAdressBytes.Length <> subnetMaskBytes.Length Then
Throw New ArgumentException("Lengths of IP address and subnet mask do not match.")
End If
Dim broadcastAddress As Byte() = New Byte(ipAdressBytes.Length - 1) {}
For i As Integer = 0 To broadcastAddress.Length - 1
broadcastAddress(i) = CByte(ipAdressBytes(i) Or (subnetMaskBytes(i) Xor 255))
Next
Return New IPAddress(broadcastAddress)
End Function
Private Sub bCalculate_Click(sender As Object, e As EventArgs) Handles bCalculate.Click
Try
If (IpSubnet.Text = IPAddress.Broadcast.ToString()) Then
IpBroadcast.Text = IPAddress.Broadcast.ToString()
Else
IpBroadcast.Text = GetBroadcastAddress(IPAddress.Parse(IpIP.Text), IPAddress.Parse(IpSubnet.Text)).ToString()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub bOK_Click(sender As Object, e As EventArgs) Handles bOK.Click
_properties.Broadcast.Text = IpBroadcast.Text
Close()
End Sub
End Class