7 Free .Net Development and Architecture e-Books!

Thank you to MSDN for re-distributing Anoop’s blog post on these seven FREE .Net development e-Books! The last group are Scribd from DZone, and you have to have a DZone account and be logged in to download, but the rest are freely downloadable from the websites. Here’s the title and link to each:

Foundations of Programming
Microsoft Application Architecture Guide, 2nd Ed.
Rob Miles C# YellowBook 2010
Threading in C#
Improving .Net Application Performance and Stability
Applying Design Patterns

DZone Reference Cards
Getting Started With WCF 4.0
Getting Started with Silverlight + Expression Blend
Essential F#

Enjoy the freebies!

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube

Getting local IP address programmatically in Windows 7

I created a small client app for my company that required the local IP address (assigned by DHCP) to determine what site it was on. It reads the second octet value, which is consistent with each of our buildings in our enterprise. From here, I can determine what content to load so no matter where the PC is placed, it automatically grabs content only specific to that location.

Anyway, when testing this application on Windows 7 it doesn’t load any content. Initial troubleshooting indicates the IP address is not resolving as it would on a Windows XP machine. I dug into the code today and noticed when run on Windows 7 the IP Address was coming up something like this:

fe80::a0b4:2c9d:2542:6b73%11

This was achieved by using System.Net and the following C# code:

string hostname = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(hostname);
IPAddress[] ip = ipEntry.AddressList;

Then ip[0].ToString() will give you the IP Address, or in Windows 7 case, the IPv6 address you see above. Let me show you what worked for me:

First, make sure you’re referencing the System.Linq namespace in addition to System.Net.

Next, replace the above code with the following:

string hostname = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostByName(hostname);
string ip = ipEntry.AddressList.FirstOrDefault().ToString();

Note that Dns.GetHostByName is obsolete, and eventually will be replaced. However, the recommended “GetHostEntry” failed to return the IPv4 address I needed, but instead returned the IPv6 address mentioned above. I welcome feedback on what I might be doing wrong or how to improve on this process, but for now this solves my Windows 7 IP Address issue. Hope this helps someone else.

UPDATE: Thanks to the anonymous comment left that clarified my unfamiliarity with IPv6 address syntax. Corrections were made accordingly.

Eric

Eric Oszakiewski is a professional software developer based in Scottsdale, AZ with over 35 years of IT experience, and 19 years Native American Gaming experience. He is currently working as a Sr .Net/SharePoint Developer for General Motors, and also as a consultant.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle PlusYouTube