[Mono-list] Getting list of IPAddress available

Jim P. mono@cinemanage.com
Mon, 29 Nov 2004 12:14:59 -0800


This is a multi-part message in MIME format.

------=_NextPart_000_0028_01C4D60D.0F0289C0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I'm working with System.Net.Sockets.  I'm trying to get a listing of the
available IPAddress on the machine.  When I run this on my Windows XP
box
I get the IP of my NIC: 192.168.2.11.  But when I run this on my Fedora
Core 2 Server I only get 127.0.0.1.  I have 1 NIC on this box that works
fine and is on IP 192.168.2.101.
 
Any idea why the NIC on THE PC would show up fine but not on the Fedora
box?
 
Here is the code I'm using to check for the IPs:
 
using System;
using System.Net;
 
public class Address
{
    public static int Main (string [] args)
    {
     // Getting Ip address of local machine...
     Console.WriteLine ("Local Machine's Host Name: " + 
Dns.GetHostName());
     
 // get the IP address list..
 IPHostEntry ipEntry = Dns.GetHostByName (Dns.GetHostName());
 IPAddress [] addr = ipEntry.AddressList;
 
 Console.WriteLine ("Number of available IPs: " +addr.Length);  
 
 for (int i = 0; i < addr.Length; i++)
 {
     Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString ());
 }
 return 0;
    }    
 }
 
 
Thanks

------=_NextPart_000_0028_01C4D60D.0F0289C0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DProgId content=3DWord.Document>
<meta name=3DGenerator content=3D"Microsoft Word 10">
<meta name=3DOriginator content=3D"Microsoft Word 10">
<link rel=3DFile-List href=3D"cid:filelist.xml@01C4D60D.0B848690">
<o:SmartTagType =
namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags"
 name=3D"place"/>
<!--[if gte mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
pre
	{margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Courier New";
	mso-fareast-font-family:"Times New Roman";}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple =
style=3D'tab-interval:.5in'>

<div class=3DSection1><pre><font size=3D2 face=3D"Courier New"><span
style=3D'font-size:10.0pt'>I'm working with <span =
class=3DSpellE>System.Net.Sockets</span>.<span =
style=3D'mso-spacerun:yes'>&nbsp; </span>I'm trying to get a listing of =
the<o:p></o:p></span></font></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>available</span></font></span> <span
class=3DSpellE>IPAddress</span> on the machine.<span =
style=3D'mso-spacerun:yes'>&nbsp; </span>When I run this on my Windows =
XP box<o:p></o:p></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>I get the =
IP of my NIC: 192.168.2.11.<span style=3D'mso-spacerun:yes'>&nbsp; =
</span>But when I run this on my =
Fedora<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>Core 2 =
Server I only get 127.0.0.1.<span style=3D'mso-spacerun:yes'>&nbsp; =
</span>I have 1 NIC on this box that =
works<o:p></o:p></span></font></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>fine</span></font></span> and is on IP =
192.168.2.101.<o:p></o:p></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>Any idea =
why the NIC on THE PC would show up fine but not on the =
Fedora<o:p></o:p></span></font></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>box</span></font></span>?<o:p></o:p></pre><pre=
><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>Here is =
the code I'm using to check for the <span
class=3DSpellE>IPs</span>:<o:p></o:p></span></font></pre><pre><font =
size=3D2
face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
<o:p></o:p></span></font></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>using</span></font></span> =
System;<o:p></o:p></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>using</span></font></span> =
System.Net;<o:p></o:p></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
<o:p></o:p></span></font></pre><pre><span
class=3DGramE><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>public</span></font></span> class =
Address<o:p></o:p></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>{<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span><span
class=3DGramE>public</span> static <span class=3DSpellE>int</span> =
</span></font><st1:place>Main</st1:place> (string [] <span
class=3DSpellE>args</span>)<o:p></o:p></pre><pre><font size=3D2 =
face=3D"Courier New"><span
style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; =
</span>{<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp; </span>// <span
class=3DGramE>Getting</span> <span class=3DSpellE>Ip</span> address of =
local machine...<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>Console.WriteLine</span> (&quot;Local Machine's Host =
Name: &quot; + <o:p></o:p></span></font></pre><pre><span
class=3DSpellE><span class=3DGramE><font size=3D2 face=3D"Courier =
New"><span
style=3D'font-size:10.0pt'>Dns.GetHostName</span></font></span></span><sp=
an
class=3DGramE>(</span>));<o:p></o:p></pre><pre><font size=3D2 =
face=3D"Courier New"><span
style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp; =
</span><o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;</span>// get the IP address list<span
class=3DGramE>..</span><o:p></o:p></span></font></pre><pre><font =
size=3D2
face=3D"Courier New"><span style=3D'font-size:10.0pt'> <span =
class=3DSpellE>IPHostEntry</span> <span
class=3DSpellE>ipEntry</span> =3D <span =
class=3DSpellE>Dns.GetHostByName</span> (<span
class=3DSpellE><span class=3DGramE>Dns.GetHostName</span></span><span =
class=3DGramE>(</span>));<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> <span =
class=3DSpellE>IPAddress</span> [] <span
class=3DSpellE>addr</span> =3D <span =
class=3DSpellE>ipEntry.AddressList</span>;<o:p></o:p></span></font></pre>=
<pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;</span><span
class=3DSpellE>Console.WriteLine</span> (&quot;Number of available <span
class=3DSpellE>IPs</span>: &quot; +<span =
class=3DSpellE>addr.Length</span>);<span =
style=3D'mso-spacerun:yes'>&nbsp; =
</span><o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;</span><o:p></o:p></span></font></pre><p=
re><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;</span><span
class=3DGramE>for</span> (<span class=3DSpellE>int</span> <span =
class=3DSpellE>i</span> =3D 0; <span
class=3DSpellE>i</span> &lt; <span class=3DSpellE>addr.Length</span>; =
<span
class=3DSpellE>i</span>++)<o:p></o:p></span></font></pre><pre><font =
size=3D2
face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
{<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp;&nbsp; </span><span
class=3DSpellE>Console.WriteLine</span> (&quot;IP Address {0}: {1} =
&quot;, <span
class=3DSpellE>i</span>, <span class=3DSpellE>addr</span>[<span =
class=3DSpellE>i</span>].<span
class=3DSpellE>ToString</span> =
());<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
}<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> <span =
class=3DGramE>return</span> 0;<o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; </span>}<span =
style=3D'mso-spacerun:yes'>&nbsp;&nbsp;&nbsp; =
</span><o:p></o:p></span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'><span =
style=3D'mso-spacerun:yes'>&nbsp;</span>}<o:p></o:p></span></font></pre>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Thanks<o:p></o:p></span></font></p>

</div>

</body>

</html>

------=_NextPart_000_0028_01C4D60D.0F0289C0--