ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have finally got my wake on LAN function working by using the depicus website WOL ovre internet http://www.depicus.com/wake-on-lan/woli.aspx (for those who are interested). I'm being a little paranoid and I want to make a similar webpage which does the same thing just incase the Depicus website closes down etc. On the depicus page it gives a stripped down version of .NET code for creating the magic packet. I'm not a hardcore programmer and I tried to copy the code to my website (at uni). Unfortunately I dont know how to manipulate the .NET code to make it into the usable type of code as on the depicus page. I was wondering if anyone who has the experience had any suggestions (or could help) on how to create the webpage page. I may invest time in learning html / .net from scratch but I dont know if that's over kill. Hence i need to have someone look at it before I commence. Any advice would be much appreciated.
The code is as follows:
Code:
<%@ Import Namespace = "System.Net" %>
<%@ Import Namespace = "System.Net.Sockets" %>
<%@ Import Namespace = "System.Net.Dns"%>
<%@ Import Namespace = "System.Text"%>
<script language="vb" runat="server">
Private Function InvertBinary(ByVal x As String) As String
Dim ch As Char
Dim len As Integer = CStr(x).Length
For Each ch In CStr(x)
If ch = "1" Then
InvertBinary += "0"
Else
InvertBinary += "1"
End If
Next
End Function
Private Function OrIt(ByVal x As Long, ByVal y As Long) As String
'Pad out
Dim xx As String
xx = CStr(x)
While xx.Length < 8
xx = "0" + xx
End While
Dim yy As String
yy = CStr(y)
While yy.Length < 8
yy = "0" + yy
End While
For c As Integer = 0 To 7
If xx.Chars(c) = "1" Or yy.Chars(c) = "1" Then
OrIt += "1"
Else
OrIt += "0"
End If
Next
End Function
Private Function ToBinary(ByVal x As Long) As String
Dim temp As String = ""
Do
If x Mod 2 Then
temp = "1" + temp
Else
temp = "0" + temp
End If
x = x \ 2
If x < 1 Then Exit Do
Loop
While temp.Length < 8
temp = "0" + temp
End While
Return temp
End Function
Private Function ToInteger(ByVal x As Long) As String
Dim temp As String
Dim ch As Char
Dim multiply As Integer = 1
Dim subtract As Integer = 1
Dim len As Integer = CStr(x).Length
For Each ch In CStr(x)
For len = 1 To CStr(x).Length - subtract
multiply = multiply * 2
Next
multiply = CInt(ch.ToString) * multiply
temp = multiply + temp
subtract = subtract + 1
multiply = 1
Next
Return temp
End Function
Private Sub btnWakeUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim udpClient As New UdpClient
Dim buf(101) As Char
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(buf)
For x As Integer = 0 To 5
sendBytes(x) = CInt("&HFF")
Next
Dim MacAddress As String
MacAddress = Replace(edtMac.Text, "-", "")
Dim i As Integer = 6
For x As Integer = 1 To 16
sendBytes(i) = CInt("&H" + MacAddress.Substring(0, 2))
sendBytes(i + 1) = CInt("&H" + MacAddress.Substring(2, 2))
sendBytes(i + 2) = CInt("&H" + MacAddress.Substring(4, 2))
sendBytes(i + 3) = CInt("&H" + MacAddress.Substring(6, 2))
sendBytes(i + 4) = CInt("&H" + MacAddress.Substring(8, 2))
sendBytes(i + 5) = CInt("&H" + MacAddress.Substring(10, 2))
i += 6
Next
Dim myAddress As String
'' Split user IP address
Dim myIpArray() As String
Dim a, b, c, d As Int64
myIpArray = edtIpAddress.Text.Split(".")
For i = 0 To myIpArray.GetUpperBound(0)
Select Case i
Case Is = 0
a = Convert.ToInt64(myIpArray(i))
Case Is = 1
b = Convert.ToInt64(myIpArray(i))
Case Is = 2
c = Convert.ToInt64(myIpArray(i))
Case Is = 3
d = Convert.ToInt64(myIpArray(i))
End Select
Next
Dim mySubnetArray() As String
Dim sm1, sm2, sm3, sm4 As Int64
mySubnetArray = edtSubnetMask.Text.Split(".")
For i = 0 To mySubnetArray.GetUpperBound(0)
Select Case i
Case Is = 0
sm1 = Convert.ToInt64(mySubnetArray(i))
Case Is = 1
sm2 = Convert.ToInt64(mySubnetArray(i))
Case Is = 2
sm3 = Convert.ToInt64(mySubnetArray(i))
Case Is = 3
sm4 = Convert.ToInt64(mySubnetArray(i))
End Select
Next
myAddress = ToInteger(OrIt(ToBinary(a), InvertBinary(ToBinary(sm1)))) & "." & ToInteger(OrIt(ToBinary(b), InvertBinary(ToBinary(sm2)))) & _
"." & ToInteger(OrIt(ToBinary(c), InvertBinary(ToBinary(sm3)))) & "." & ToInteger(OrIt(ToBinary(d), InvertBinary(ToBinary(sm4))))
udpClient.Send(sendBytes, sendBytes.Length, myAddress, CInt(edtPortNo.Text))
lblSent.Text = " Magic Packet sent to " & myAddress
End Sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>www.depicus.com</title>
</head>
<body>
<form id=myForm method=post runat="server">
<asp:textbox id=edtMac runat="server" CssClass="myInput">00-90-27-A3-22-FE</asp:TextBox><br>
<asp:textbox id=edtIpAddress runat="server" MaxLength="15" CssClass="myInput">217.204.255.55</asp:TextBox><br>
<asp:textbox id=edtSubnetMask runat="server" MaxLength="15" CssClass="myInput">255.255.255.240</asp:TextBox><br>
<asp:textbox id=edtPortNo runat="server" MaxLength="5" CssClass="myInput">7</asp:TextBox><br>
<asp:button id=btnWakeUp runat="server" onclick="btnWakeUp_Click" Text="Wake On Wan" CssClass="bluebutton"></asp:Button>
<asp:Label id=lblSent runat="server" CssClass="errortext"><p> </p></asp:Label>
</form>
</body>
</html>
Yes and separate the vb.net code from the html server code. Look at the .Net quick start. If I remember it just and include of the vb.net code at the top of the aspx page.
Good Luck!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.