[Mono-aspnet-list] RES: URGENT HELP C# + DEBIAN

Edgar edgarrc at gmail.com
Mon Jul 16 11:09:39 UTC 2012


Hi,

 

I don't mean to give a C# alternative for everything, but easy things like
this, simple scripting, would be better if you do using bash scripts. The
following code will do what you want, put in a file, set it to executable
(chmod +x filename) then run it on system startup.

 

 

-------------------

#!/bin/bash

 

set - `ifconfig | grep -B 1 inet | head -1`

MAC=$5

 

j=$(cat /usr/mc.txt)

 

echo "Actual mac address is: "$5

echo "Mac address saved is: " $j

 

if [ "$5" != "$j" ]; then

  echo "Changed"

  /sbin/shutdown -h now

else

  echo "not changed"

fi

-----------------

 

Best regards,

 

Edgar Rocha Carvalho

 

 

 

 

 

 

 

De: mono-aspnet-list-bounces at lists.ximian.com
[mailto:mono-aspnet-list-bounces at lists.ximian.com] Em nome de aaron.ullal
Enviada em: quinta-feira, 12 de julho de 2012 16:34
Para: mono-aspnet-list at lists.ximian.com
Assunto: [Mono-aspnet-list] URGENT HELP C# + DEBIAN

 

Hey guys! I urgently need your help
<http://n4.nabble.com/images/smiley/anim_jump.gif> Ok so what im trying to
do is this: 


i have a debian server and i saved its mac address on a txt file in the usr
folder. What i want to do is that every time i start the machine the script
i'm trying to do should check the current mac address and compare it to the
one saved on the txt file. If they don't match than the machine should
shutdown.


I'm not very familiar with debian so i programmed the script in c#..it looks
like this using System; using System.Collections.Generic; using System.Linq;
using System.Text; using System.IO; using System.Net.NetworkInformation;
namespace Get_macaddress { class Program { static void Main(string[] args) {
string newmc = Convert.ToString(GetMacAddress()); //current mac address
string mc = File.ReadAllText(@"/usr/mc.txt"); //mac address saved on a txt
file previously if (newmc != mc) //shutdown if the mac addresses dont match
{ System.Diagnostics.Process.Start("shutdown.exe", "-s -t 0"); } } static
string GetMacAddress() { string macAddresses = ""; foreach (NetworkInterface
nic in NetworkInterface.GetAllNetworkInterfaces()) { // Only consider
Ethernet network interfaces, thereby ignoring any // loopback devices etc.
if (nic.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue; if
(nic.OperationalStatus == OperationalStatus.Up) { macAddresses +=
nic.GetPhysicalAddress().ToString(); break; } } return macAddresses; } } }
THAN what i created a txt file containing the code and i renamed in
shutdown.cs and transferred it on debian machine. 


When i run the mcs shutdown.cs command i get this error : CS0234: The type
or namespace name 'NetworkInformation' does not exist i the namespace
'System.Net'. Are you missing an assembly reference?


I don't know what to do guys as i said i'm not very familiar with debian nor
with mono honestly..if you guys could help me out would be fantastic. 

  _____  

View this message in context: URGENT
<http://mono.1490590.n4.nabble.com/URGENT-HELP-C-DEBIAN-tp4650386.html>
HELP C# + DEBIAN
Sent from the Mono -
<http://mono.1490590.n4.nabble.com/Mono-ASP-NET-f1539225.html>  ASP.NET
mailing list archive at Nabble.com.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20120716/6409c407/attachment.html>


More information about the Mono-aspnet-list mailing list