Monthly Archives: February 2014
Tracert implementation in C#
While I was looking for a tracert method that I could use for an application of mine I noticed that the .NET framework doesn’t provide one out of the box, so I decided to create one that matched my requirements.
The method below works in the exact same fashion the tracert method works. Providing
the method with the IP address, the max number of hops you would like to receive and a timeout value for the hops will allow you to track down the route your data will travel in order to get to their destination, as well as the time (in milliseconds) it will take for each hop.
Main method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /// <summary> /// Traces the route which data have to travel through in order to reach an IP address. /// </summary> /// <param name="ipAddress">The IP address of the destination.</param> /// <param name="maxHops">Max hops to be returned.</param> public IEnumerable<TracertEntry> Tracert(string ipAddress, int maxHops, int timeout) { IPAddress address; // Ensure that the argument address is valid. if (!IPAddress.TryParse(ipAddress, out address)) throw new ArgumentException(string.Format("{0} is not a valid IP address.", ipAddress)); // Max hops should be at least one or else there won't be any data to return. if (maxHops < 1) throw new ArgumentException("Max hops can't be lower than 1."); // Ensure that the timeout is not set to 0 or a negative number. if (timeout < 1) throw new ArgumentException("Timeout value must be higher than 0."); Ping ping = new Ping(); PingOptions pingOptions = new PingOptions(1, true); Stopwatch pingReplyTime = new Stopwatch(); PingReply reply; do { pingReplyTime.Start(); reply = ping.Send(address, timeout, new byte[] { 0 }, pingOptions); pingReplyTime.Stop(); string hostname = string.Empty; if (reply.Address != null) { try { hostname = Dns.GetHostByAddress(reply.Address).HostName; // Retrieve the hostname for the replied address. } catch (SocketException) { /* No host available for that address. */ } } // Return out TracertEntry object with all the information about the hop. yield return new TracertEntry() { HopID = pingOptions.Ttl, Address = reply.Address == null ? "N/A" : reply.Address.ToString(), Hostname = hostname, ReplyTime = pingReplyTime.ElapsedMilliseconds, ReplyStatus = reply.Status }; pingOptions.Ttl++; pingReplyTime.Reset(); } while (reply.Status != IPStatus.Success && pingOptions.Ttl <= maxHops); } |
Microsoft Office 2013 Service Pack 1 (SP1) is now available
Microsoft Office 2013 Service Pack 1 is now available to download. This update offers improvements in stability, performance, and security. In addition, the SP1 update contains all the previously released updates as well as some unreleased ones.
For more detailed information visit http://support.microsoft.com/kb/2817430.
This update can be applied to the following products:
- Microsoft Office Home and Business 2013
- Microsoft Office Home and Student 2013
- Microsoft Office Personal 2013
- Microsoft Office Professional 2013
- Microsoft Office Professional Academic 2013
- Microsoft Office Professional Plus 2013
- Microsoft Office Standard 2013
Download Links
Posted in Microsoft, Software Updates.
Windows 8.1 Update 1 to be released this spring (2014)
Joe Belfiore has mentioned in the Windows blog page that Windows 8.1 Update 1 is currently scheduled to be released this spring.
Over the next few months, we’ll continue to deliver innovation and progression with an update to Windows 8.1, coming this spring.
Not much information has been released yet as to what changes the new update will bring to the users, but based on the things pointed out in an official post it seems that desktop user experience will be one of the main things they want to improve.
- We’ll enable our partners to build lower cost hardware for a great Windows experience at highly competitive price points.
- We are making improvements to the user interface that will naturally bridge touch and desktop, especially for our mouse and keyboard users. We have a number of targeted UI improvements that keep our highly satisfying touch experience intact, but that make the UI more familiar and more convenient for users with mouse/keyboard. Don’t worry, we still LOVE and BELIEVE IN touch… but you’ll like how much more smooth and convenient these changes make mouse and keyboard use!
- We are enhancing support for enterprise customers via a few tweaks, particularly including features that greatly improve IE8 compatibility in Internet Explorer 11, which is especially critical for web-based line of business applications. Additionally, we’re extending mobile device management capabilities and making deployment easier.
As a desktop user I welcome any chances aimed to improve the functionality for keyboard and mouse users and I am eager to see what the update has in store for us.
What kind of features/improvements would you like to see in the new update ?
How to generate QR barcodes in C#
QR barcodes are machine-readable optical labels that contain certain information. Today we will be looking into how to generate QR codes with the use of the ZXing.Net library.
First you will need to download the ZXing.Net library from zxingnet.codeplex.com. Extract the contents of the file you have downloaded and reference the library that fits your needs in your project.
Using the example code below you will now be able to create your own QR codes.
1 2 3 4 5 6 7 8 9 10 | public Bitmap GenerateQR(int width, int height, string text) { var bw = new ZXing.BarcodeWriter(); var encOptions = new ZXing.Common.EncodingOptions() { Width = width, Height = height, Margin = 0 }; bw.Options = encOptions; bw.Format = ZXing.BarcodeFormat.QR_CODE; var result = new Bitmap(bw.Write(text)); return result; } |
Example: Calling the following method will return a Bitmap object which you can save using the Bitmap’s Bitmap.Save() method or simply display it within your application.
1 | GenerateQR(200, 200, "http://www.fluxbytes.com/csharp/generating-qr-barcode-in-c/"); |