Blog

Adventures in C# on Mono

posted 5 Dec 2014, 08:56 by Owen Brotherwood   [ updated 8 Dec 2014, 03:40 ]

Well, it is just Java in new clothes ...


using System;
using Ipcollector.Dialect;
using System.Net.Sockets;
using System.Net;


namespace IPcollector
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            // very basic input to get the job done
            String ipAddress = args [0];
            String port = args [1]; 
            String hostName = args [2];
            String hostState = args [3];
            String attrKey = args [4];
            String attrValue = args [5];

            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1))).TotalSeconds;

            // no error checking for now
            IPEndPoint ipEndPoint = new IPEndPoint (IPAddress.Parse (ipAddress), int.Parse (port));
            Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect (ipEndPoint);
            NetworkStream networkStream = new NetworkStream (socket, true);

            // build a very basic event
            ExternalEvent externalEvent = new ExternalEvent ();
            externalEvent.event_type = ExternalEvent.EventType.HOST;
            externalEvent.HostEvent.HostName = hostName;
            externalEvent.MessageId = unixTimestamp;
            String hostStateUpper = hostState.ToUpper();
            switch (hostStateUpper) {
            case "UP": 
                externalEvent.HostEvent.host_state = ExternalEvent.ExternalHostEvent.HostState.UP;
                break;
            case "DOWN":
                externalEvent.HostEvent.host_state = ExternalEvent.ExternalHostEvent.HostState.DOWN;
                break;
            case "UNREACHABLE":
                externalEvent.HostEvent.host_state = ExternalEvent.ExternalHostEvent.HostState.UNREACHABLE;
                break;
            }
            ExternalEvent.ExternalAttribute externalAttribute = new ExternalEvent.ExternalAttribute ();
            externalAttribute.Key = attrKey;
            externalAttribute.Value = attrValue;
            externalEvent.HostEvent.Attribute.Add (externalAttribute);

            // send event
            ExternalEvent.Serialize (networkStream, externalEvent);
        }
    }
}

Disclaimer

posted 1 Dec 2012, 11:21 by Owen Brotherwood

This product is meant for educational purposes only. Any resemblance to 
real persons, living or dead is purley coincidental. Void where 
prohibited. Some assembly required. List each check separately by bank 
number. Batteries not included. Contents may settle during shipment. 
Use only as directed. No other warranty expressed or implied. Do not 
use while operating a motor vehicle or heavy equipment. Postage will be 
paid by addressee. Subject to CAB approval.  This is not an offer to 
sell securities. Apply only to affected area. May be too intense for 
some viewers. Do not stamp. Use other side for additional listings. For 
recreational use only. Do not disturb. All models over 18 years of age. 
If condition persists, consult your physician. No user-serviceable 
parts inside. Freshest if eaten before date on carton. Subject to 
change without notice. Times approximate. Simulated picture. No postage 
necessary if mailed in the United States. Breaking seal constitutes 
acceptance of agreement. For off-road use only. As seen on TV. One size 
fits all. Many suitcases look alike. Contains a substaintial amount of 
non-tobacco ingredients. Colors may, in time, fade. We have sent the 
forms which seem to be right for you. Slippery when wet. For office use 
only. Not affiliated with the American Red Cross. Drop in any mailbox. 
Edited for television. Keep cool; process promptly. Post office will 
not deliver without postage. List was current at time of printing. 
Return to sender, no forwarding order on file, unable to forward. Not 
responsible for direct, indirect, incidental or consequential damages 
resulting from any defect, error or failure to perform.  At 
participating locations only. Not the Beatles. Penalty for private use. 
See label for sequence. Substantial penalty for early withdrawal. Do 
not write below this line. Falling rock. Lost ticket pays maximum rate. 
Your cancelled check is your recipt. Add toner. Place stamp here. Avoid 
contact with skin.  Sanitized for your protection. Be sure each item is 
properly endorsed. Sign here without admitting guilt. Slightly higher 
west of the Mississippi.  Employees and their families are not 
eligible. Beware of dog. Contestants have been briefed on some 
questions before the show. Limited time offer, call now to insure 
prompt delivery. You must be present to win. No passes accepted for 
this engagement. No purchase necessary. Processed at location stamped 
in code at top of carton. Shading within a garment may occur. Use only 
in well-ventilated area. Keep away from fire or flame. Replace with 
same type.  Approved for veterans. Booths for two or more. Check here 
if tax deductible.  Some equipment shown is optional. Price does not 
include taxes. No Canadian coins. Not recommended for children. 
Prerecorded for this time zone.  Reproduction strictly prohibited. No 
solicitors. No alcohol, dogs, or horses.  No anchovies unless otherwise 
specified. Restaurant package, not for resale.  List at least two 
alternate dates. First pull up, then pull down. Call toll free before 
digging. Driver does not carry cash. Some of the trademarks mentioned
in this product appear for identification purposes only. Record
additional transactions on back of previous stub.

This supersedes all previous notices.

Android and Ubuntu

posted 19 Nov 2012, 12:22 by Owen Brotherwood

Hmm, got to write some notes.
Do not use Open JDK: download Java 6 binary.
http://www.printandweb.ca/2012/10/manually-install-oracle-jdk-6-for.html

Manually Install Oracle JDK 6 for Ubuntu 12.10
Tags: support, Ubuntu
These are my notes for 12.04 updated for Ubuntu 12.10. The process I used for 12.04 works the same for 12.10.

Most installation notes refer to the no longer available sun-java6-jdk or an individual ppm, but these notes are for manually installing the downloaded files from Oracle. I'm referring to JDK6, but you could substitute JDK7 if that's what you need.

Download Java SE 6 JDK for Linux x86 self-extracting binary
At the time of writing, the file I'm using is jdk-6u37-linux-i586.bin, but the filename will change as updates are released.
From the download folder, make the file executable
chmod a+x jdk-6u37-linux-i586.bin
Apparently there isn't a jvm folder anymore, so create one.
sudo mkdir /usr/lib/jvm
Move the file to the jvm folder
sudo mv jdk-6u37-linux-i586.bin /usr/lib/jvm/
Change to the jvm folder and run the self-extracting binary
cd /usr/lib/jvm
sudo ./jdk-6u37-linux-i586.bin
Everything will be extracted to a new jdk1.6.0_37 folder and you can delete the .bin file now.
Make symbolic links to the new java binary.
sudo ln -s -b /usr/lib/jvm/jdk1.6.0_37/jre/bin/java /etc/alternatives/java
sudo ln -s -b /usr/lib/jvm/jdk1.6.0_37/jre/bin/java /usr/bin/java
Double-check the version
java -version
Now you can easily update and switch between JDK versions directly from the source.

Get the SDK: I just got the bundle @ http://developer.android.com/sdk/index.html

http://developer.android.com/tools/projects/projects-cmdline.html
android create project --target 1 --name MyAndroidApp  --path ./MyAndroidAppProject  --activity MyAndroidAppActivity  --package com.example.myandroid


ant debug
android avd
adb -install <apk>


Carrier IQ

posted 5 Dec 2011, 11:49 by Owen Brotherwood   [ updated 5 Dec 2011, 11:57 ]

Don't know about Carrier IQ? 
- read about Carrier IQ and come back

This pre-Christmas revelation is getting messy.
Once upon a time, some guy got an idea. Other guys worked long nights on the idea, with success and failures, but "eureka". Then marketing, and the selling of the idea to the manufactures. 

After various design and/or other decisions, the lawyers are now out front with jobs and dreams at stake.

How to disable Carrier IQ
 
Apple allows opt out of sending diagnostics data, 

Android?
- who knows, not "standard" across platform/hardware suppliers

Android Certificates

posted 1 Dec 2011, 13:45 by Owen Brotherwood

Android, hmm, well sometimes y have to import certificates

Root, Intermediate or Server: Base64 X.509 and name it with extension .crt
Personal: PKCS#12 and name it with extension .p12

Send them by mail, and click on attachment...

For joining a wireless network, use anonymous identity.

Tested on Galaxy Tab

1-5 of 5