Comment recuperer l'addresse IP local?

Tellurian Messages postés 15 Date d'inscription vendredi 5 septembre 2003 Statut Membre Dernière intervention 10 mars 2006 - 27 mai 2004 à 14:31
gfpl Messages postés 172 Date d'inscription samedi 11 août 2012 Statut Membre Dernière intervention 9 avril 2011 - 11 juil. 2005 à 18:06
Voila j'ai un petit pb avec c# et la programmation network:

je debute en c# pour le moment et tou ce que g trouvé pour obtenir l'addresse IP local c'est :

System.Net.IPHostEntry localIP = System.Net.Dns.Resolve System.Net.Dns.GetHostName());      

this.lblLocalIP.Text = localIP.AddressList.GetValue(0).ToString();


je pensse qu'il y a + simple

merci d'avance

6 réponses

cs_Crazyht Messages postés 1522 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 21 août 2010 8
27 mai 2004 à 15:17
Euh non pas vraiement a part mettre un using System.Net en haut :)

et peut-etre mais on gagne presque rien :) :
this.lblLocalIP.Text = Dns.GetHostByName (Dns.GetHostName).AddressList[0];

A++

:-p Crazyht :)

[Admin Codes-Sources]
[Membre Developer-Association]

Un programmeur, c'est quelqu'un qui résout pour toi, de façon incompréhensible, un problème que tu ignorais avoir...
0
Tellurian Messages postés 15 Date d'inscription vendredi 5 septembre 2003 Statut Membre Dernière intervention 10 mars 2006
27 mai 2004 à 15:32
Merci!

en fait je pose cette question pour pouvoir créé un chat pour un reseau local, et comme je programme en vb depuis + de 5 ans et en C++ depuis plus de 2 je me demande si on ne pourrai pas utiliser un contrôle activex du genre de Winsock en vb?

:-p
0
cs_Crazyht Messages postés 1522 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 21 août 2010 8
27 mai 2004 à 16:23
Erf moi je te le conseille pas, personnellement je trouve que les classe .NET sont bien plus efficaces que l'activeX Winsock de m@?!@

A++

:-p Crazyht :)

[Admin Codes-Sources]
[Membre Developer-Association]

Un programmeur, c'est quelqu'un qui résout pour toi, de façon incompréhensible, un problème que tu ignorais avoir...
0
Tellurian Messages postés 15 Date d'inscription vendredi 5 septembre 2003 Statut Membre Dernière intervention 10 mars 2006
27 mai 2004 à 16:28
en effet je vien de me rendre compte qu'il y a beacoup + de fonctions avec l'espace System.Net

merci du conseil!!!

:approve)

@+
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
5 déc. 2004 à 18:10
Par exemple :

string hôte = Dns.GetHostName();
IPHostEntry iphe = Dns.Resolve(hôte);
string ip = iphe.AddressList[0].ToString();
Console.WriteLine("Votre Ip est: " + ip);
Console.ReadLine();

A AdressList[0] est ce qu'il peut y avoir autre chose que 0
C'est un tableau d'adresse ??????????

Merci de m'aider!!!!!!

RM50man
0
gfpl Messages postés 172 Date d'inscription samedi 11 août 2012 Statut Membre Dernière intervention 9 avril 2011
11 juil. 2005 à 18:06
bonjour j essaie deseperement (je suis debutant d'afficher mon ip et je n'y arrive pas :(



voici la source meme avec vos example je ne m en sort pas du tout



le but dans un premiers temps est d afficher l ip dans un texte box



voici la source



////



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.Net;





namespace WindowsApplication24

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.TextBox lblLocalIP;

private System.Windows.Forms.Button button1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;



public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



//

// TODO: Add any constructor code after InitializeComponent call

//

}



/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.lblLocalIP = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// lblLocalIP

//

this.lblLocalIP.Location = new System.Drawing.Point(56, 72);

this.lblLocalIP.Name = "lblLocalIP";

this.lblLocalIP.Size = new System.Drawing.Size(160, 20);

this.lblLocalIP.TabIndex = 0;

this.lblLocalIP.Text = "lblLocalIP";

//

// button1

//

this.button1.Location = new System.Drawing.Point(176, 136);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(64, 56);

this.button1.TabIndex = 1;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.button1);

this.Controls.Add(this.lblLocalIP);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);



}

#endregion



/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}



private void Form1_Load(object sender, System.EventArgs e)

{





}



private void button1_Click(object sender, System.EventArgs e)

{

this.lblLocalIP.Text = localIP.AddressList.GetValue(0).ToString();



}





}

}

//////
0
Rejoignez-nous