Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-05-2006, 08:02 AM
|
#1
|
|
Member
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277
Rep:
|
Incorporating .NET code into a webpage
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>
|
|
|
|
12-06-2006, 03:39 PM
|
#2
|
|
Senior Member
Registered: Mar 2004
Location: Wales, UK
Distribution: Debian, Ubuntu
Posts: 1,075
Rep:
|
IIRC the current version of Mono supports C#, but not VB.NET, so you will need to convert this code into C# in order to run it on a Linux server.
|
|
|
|
12-06-2006, 05:16 PM
|
#3
|
|
Member
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277
Original Poster
Rep:
|
Okay, I will have a word withsomeone on the conversion. Thanks for the direction
|
|
|
|
12-06-2006, 05:52 PM
|
#4
|
|
Senior Member
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690
Rep:
|
I would try to use code behind as much as possible instead of embedding the code in a webpage.
|
|
|
|
12-07-2006, 04:33 AM
|
#5
|
|
Member
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277
Original Poster
Rep:
|
Do you mean I can somehow create a standalone application which can do the same thing?
|
|
|
|
12-07-2006, 06:27 PM
|
#6
|
|
Senior Member
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690
Rep:
|
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!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:17 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|