Vérifier qu'un port est bien ouvert sur mon serveur, et à distance...

remilafouine Messages postés 32 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 11 juin 2007 - 1 oct. 2005 à 15:54
remilafouine Messages postés 32 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 11 juin 2007 - 1 oct. 2005 à 18:08
Bonjour à toutes et à tous !

Comme je l'ai dis dans le sujet, je voudrais pouvoir vérifier qu'un port est bien ouvert sur mon serveur réseau, tout ça à partir d'un programme en VB .Net sur mon poste dans mon réseau local. J'ai demandé à un copain de classe, qui m'a parlé des sockets. J'ai donc jeté un petit regard sur la librairie en ligne de MSDN, mais franchement; j'y comprend pas grand chose...

Ce que je voudrais plus exactement, c'est que lors d'un clic sur le bouton "Button1", mon programme esaaye de se connecter au port désiré, et si il arrive à s'y connecter, qu'il m'affiche dans une TextBox un texte du genre "le port est bien ouvert"...

Merci de votre aide !

2 réponses

cs_MasterHack Messages postés 586 Date d'inscription jeudi 18 septembre 2003 Statut Membre Dernière intervention 13 février 2008 2
1 oct. 2005 à 16:07
Salut,
Utilise le tcpclient est essayer de scanner le port ouvert ds ta machine/machine distante.
jette un coup d'oeil ds system.net.sockets
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetsockets.asp

<HR>

Life is short...Learn more
Copy Rights <> Rights to Copy
0
remilafouine Messages postés 32 Date d'inscription jeudi 20 janvier 2005 Statut Membre Dernière intervention 11 juin 2007 1
1 oct. 2005 à 18:08
J'ai essayé d'intégrer un peu comme j'ai pu ce code, mais ca ne marche pas... j'ai un peu modifié le code pour l'intégrer dans la gestion du clic sur le bouton... Voilà le code :



Private
Sub Button1_Click(
ByVal sender
As System.Object,
ByVal e
As System.EventArgs)
Handles Button1.Click



Dim server
As
String =
Me.TextBox1.Text



Try



' Create a TcpClient.



' Note, for this client to work you need to have a TcpServer



' connected to the same address as specified by the server, port



' combination.



Dim port
As Int32 = 21



Dim client
As
New TcpClient(server, port)



Dim Message
As
String



' Translate the passed message into ASCII and store it as a Byte array.



Dim data
As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Message)



' Get a client stream for reading and writing.



' Stream stream = client.GetStream();



Dim stream
As NetworkStream = client.GetStream()



' Send the message to the connected TcpServer.


stream.Write(data, 0, data.Length)



' Receive the TcpServer.response.



' Buffer to store the response bytes.


data =
New [Byte](256) {}



' String to store the response ASCII representation.



Dim responseData
As [String] = [String].Empty



' Read the first batch of the TcpServer response bytes.



Dim bytes
As Int32 = stream.Read(data, 0, data.Length)


responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)


Console.WriteLine("Received: {0}", responseData)



' Close everything.


client.Close()



Catch e
As ArgumentNullException



Me.TextBox2.Text = "ArgumentNullException: {0}"



Catch e
As SocketException



Me.TextBox2.Text = "ArgumentException: {0}"



End
Try



End
Sub

J'ai mis en rouge et en gras ce que Visual Studio .Net 2003 me souligne.
Comment faire pour résoudre ce problème ?
0
Rejoignez-nous