I am very new to coding and have been given a project at work to build a syslog and SNMP trap receiver i have got the syslog working ok but am stuck on the trap portion of the program. I can receive the snmp trap using a simple udp listener and have the data in a byte array but when using ASCII or unicode the data is garbled. i understand that SNMP is encoded in ASN.1 but am unable to figure out how to decode this.
Below is what i have i need to get the data out of the array "Data" into a string so that i can add this to both the email and the log file. This would replace the string Data2.
any help you guys could give would be great even if it's just an easier way to write what i have done so far, as i say am very new to coding so am probably doing things the hard way LOL. Also if you could explain the changes i would really like to understand this.
thanks in advance.
UdpClient SNMP = new UdpClient(162);
IPEndPoint EP = null;
bool done = true;
while (done)
{
Console.WriteLine("Waiting for Broadcast");
byte[] Data = SNMP.Receive(ref EP);
string Data2 = Encoding.ASCII.GetString(Data);
string subject = "SNMP Condition Matched" + Data2;
Console.WriteLine(DateTime.Now.ToString() + "Recivied SNMP Trap" + Data2);
using (StreamWriter D = new StreamWriter("C:\\syslog\\syslog.txt"))
{
D.WriteLine(DateTime.Now.ToString() + "Recivied SNMP Trap" + Data2);
}
ArrayList Config = new ArrayList();
using (StreamReader E = new StreamReader("C:\\syslog\\config.ini"))
{
while (!E.EndOfStream)
{
string T = E.ReadLine();
Config.Add(T);
}
E.Close();
}
if (!Config.Contains(Data2))
{
Email(subject, Data2);
}

New Topic/Question
Reply



MultiQuote





|