PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2025 → [WD15] Je cherche a savoir si un port (le 4900 en TCP) est ouvert
[WD15] Je cherche a savoir si un port (le 4900 en TCP) est ouvert
Débuté par webmaster, 31 mar. 2010 15:36 - 9 réponses
Posté le 31 mars 2010 - 15:36
bonjour,

Je cherche a savoir si un port (le 4900 en TCP) est ouvert ou non chez un client. Il y a bien netstat, mais la reponse est trop compliquée.
avez vous une solution pour affichier Port 4900 TCP ouvert : OUI / NON

Merci
Posté le 31 mars 2010 - 19:53
Tu peux essayer dans une fenêtre prompt DOS la commande :
telnet adresse_ou_nom_machine 4900
Si l'écran devient noir, c'est que tu as pu te connecter. Le port est donc ouvert

ex: telnet 192.168.0.1 4900
telnet monserveur.mondomaine 4900
Posté le 01 avril 2010 - 01:14
Merci, je vais essayer. Mais j'aurais préfére obtenir une reponse Oui/Non pour l'afficher dans un programme windev
Posté le 01 avril 2010 - 10:52
Bonjour,

> Merci, je vais essayer. Mais j'aurais préfére obtenir une reponse Oui/Non pour l'afficher dans un programme windev

SI SocketConnecte("Test",4900,sAdresseMachine) ALORS
RENVOYER "OUI"
SINON
RENVOYER "NON"
FIN
Posté le 01 avril 2010 - 13:11
Ca me renvoi OUI alors que mon port 4900 est fermé en TCP
Posté le 01 avril 2010 - 19:46
bonjour
si joint du code testé sous xp pro qui est une écriture de la commande :
netstat -a -n
mais pour le moment il n'y a que le tcp (l'udp est en cours...) et j'ai
ajouté le code de l'état (ca mange pas de pain...)
J'ai mis ça dans une collection : procIP
Pour tester : Trace(NetStat())

nota : Il y a des déclarations inutiles mais je ferais la purge plus tard...


****************************************
* DECLARATION DE LA COLLECTION procIP
****************************************
CONSTANT
AF_INET = 2
AF_INET6 = 10
//
TCP_TABLE_BASIC_LISTENER = 0 // A MIB_TCPTABLE table that contains all
listening (receiving only) TCP endpoints on the local computer is returned
to the caller.
TCP_TABLE_BASIC_CONNECTIONS = 1 // A MIB_TCPTABLE table that contains all
connected TCP endpoints on the local computer is returned to the caller.
TCP_TABLE_BASIC_ALL = 2 // A MIB_TCPTABLE table that contains all TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_LISTENER = 3 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID that contains all listening (receiving only) TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_CONNECTIONS = 4 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID that structure that contains all connected TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_ALL = 5 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID structure that contains all TCP endpoints on the
local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_LISTENER = 6 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all listening (receiving
only) TCP endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_CONNECTIONS = 7 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all connected TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_ALL = 8 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all TCP endpoints on the
local computer is returned to the caller.
//
NO_ERROR = 0
ERROR_INSUFFICIENT_BUFFER = 0x7A
// ERROR_INVALID_PARAMETER =
// The state of the TCP connection.
MIB_TCP_STATE_CLOSED = 1 // The TCP connection is in the CLOSED state that
represents no connection state at all.
MIB_TCP_STATE_LISTEN = 2 // The TCP connection is in the LISTEN state
waiting for a connection request from any remote TCP and port.
MIB_TCP_STATE_SYN_SENT = 3 // The TCP connection is in the SYN-SENT state
waiting for a matching connection request after having sent a connection
request (SYN packet).
MIB_TCP_STATE_SYN_RCVD = 4 // The TCP connection is in the SYN-RECEIVED
state waiting for a confirming connection request acknowledgment after
having both received and sent a connection request (SYN packet).
MIB_TCP_STATE_ESTAB = 5 // The TCP connection is in the ESTABLISHED state
that represents an open connection, data received can be delivered to the
user. This is the normal state for the data transfer phase of the TCP
connection.
MIB_TCP_STATE_FIN_WAIT1 = 6 // The TCP connection is FIN-WAIT-1 state
waiting for a connection termination request from the remote TCP, or an
acknowledgment of the connection termination request previously sent.
MIB_TCP_STATE_FIN_WAIT2 = 7 // The TCP connection is FIN-WAIT-1 state
waiting for a connection termination request from the remote TCP.
MIB_TCP_STATE_CLOSE_WAIT= 8 // The TCP connection is in the CLOSE-WAIT state
waiting for a connection termination request from the local user.
MIB_TCP_STATE_CLOSING = 9 // The TCP connection is in the CLOSING state
waiting for a connection termination request acknowledgment from the remote
TCP.
MIB_TCP_STATE_LAST_ACK = 10 // The TCP connection is in the LAST-ACK state
waiting for an acknowledgment of the connection termination request
previously sent to the remote TCP (which includes an acknowledgment of its
connection termination request).
MIB_TCP_STATE_TIME_WAIT = 11 // The TCP connection is in the TIME-WAIT state
waiting for enough time to pass to be sure the remote TCP received the
acknowledgment of its connection termination request.
MIB_TCP_STATE_DELETE_TCB= 12 // The TCP connection is in the delete TCB
state that represents the deletion of the Transmission Control Block (TCB),
a data structure used to maintain information on each TCP entry.
END
MIB_TCPTABLE est une structure
NumEntries est un entier système // The number of entries in the table.
table est un entier système // A pointer to a table of TCP connections
implemented as an array of MIB_TCPROW structures.
END
MIB_TCPROW est une structure
State est un entier système // The state of the TCP connection
LocalAddr est un entier sans signe sur 4 octets // The local IPv4 address
for the TCP connection on the local computer. A value of zero indicates the
listener can accept a connection on any interface.
LocalPort est un entier système // The local port number in network byte
order for the TCP connection on the local computer.
RemoteAddr est un entier sans signe sur 4 octets // The IPv4 address for the
TCP connection on the remote computer. When the dwState member is
MIB_TCP_STATE_LISTEN, this value has no meaning.
RemotePort est un entier système // The remote port number in network byte
order for the TCP connection on the remote computer. When the dwState member
is MIB_TCP_STATE_LISTEN, this member has no meaning.FIN
END
//--------------------
MIB_TCPTABLE_OWNER_PID est une structure
NumEntries est un entier système // The number of MIB_TCPROW_OWNER_PID
elements in the table.
table est un entier système // Array of MIB_TCPROW_OWNER_PID structures
returned by a call to GetExtendedTcpTable.
END
MIB_TCPROW_OWNER_PID est une structure
State est un entier système // The state of the TCP connection.
LocalAddr est un entier système // The local IPv4 address for the TCP
connection on the local computer. A value of zero indicates the listener can
accept a connection on any interface.
LocalPort est un entier système // The local port number in network byte
order for the TCP connection on the local computer.
RemoteAddr est un entier système // The IPv4 address for the TCP connection
on the remote computer. When the dwState member is MIB_TCP_STATE_LISTEN,
this value has no meaning.
RemotePort est un entier système // The remote port number in network byte
order for the TCP connection on the remote computer. When the dwState member
is MIB_TCP_STATE_LISTEN, this member has no meaning.
OwningPid est un entier système // The PID of the process that issued a
context bind for this TCP connection.
END
//--------------------
MIB_TCP6TABLE_OWNER_PID est une structure
NumEntries est un entier système // The number of MIB_TCP6ROW_OWNER_PID
elements in the table.
table est un entier système // Array of MIB_TCP6ROW_OWNER_PID structures
returned by a call to GetExtendedTcpTable.
END
MIB_TCP6ROW_OWNER_PID est une structure
LocalAddr est un entier système // The IPv6 address for the local endpoint
of the TCP connection on the local computer. A value of zero indicates the
listener can accept a connection on any interface.
LocalScopeId est un entier système // The scope ID in network byte order for
the local IPv6 address.
LocalPort est un entier système // The port number in network byte order for
the local endpoint of the TCP connection on the local computer.
RemoteAddr est un entier système // The IPv6 address of the remote endpoint
of the TCP connection on the remote computer. When the dwState member is
MIB_TCP_STATE_LISTEN, this value has no meaning.
RemoteScopeId est un entier système // The scope ID in network byte order
for the remote IPv6 address.
RemotePort est un entier système // The port number in network byte order
for the remote endpoint of the TCP connection on the remote computer.
State est un entier système // The state of the TCP connection.
OwningPid est un entier système // The PID of the local process that issued
a context bind for this TCP connection.
END
in_addr est une structure
END
//---------------------------------------
TcpState est un tableau de 12 chaînes
TcpState[MIB_TCP_STATE_CLOSED] = "CLOSED"
TcpState[MIB_TCP_STATE_LISTEN] = "LISTEN"
TcpState[MIB_TCP_STATE_SYN_SENT] = "SYN-SENT"
TcpState[MIB_TCP_STATE_SYN_RCVD] = "SYN-RECEIVED"
TcpState[MIB_TCP_STATE_ESTAB] = "ESTABLISHED"
TcpState[MIB_TCP_STATE_FIN_WAIT1] = "FIN-WAIT-1"
TcpState[MIB_TCP_STATE_FIN_WAIT2] = "FIN-WAIT-2"
TcpState[MIB_TCP_STATE_CLOSE_WAIT] = "CLOSE-WAIT"
TcpState[MIB_TCP_STATE_CLOSING] = "CLOSING"
TcpState[MIB_TCP_STATE_LAST_ACK] = "LAST-ACK"
TcpState[MIB_TCP_STATE_TIME_WAIT] = "TIME-WAIT"
TcpState[MIB_TCP_STATE_DELETE_TCB] = "TCB"

****************************************************
* PRINCIPALE FONCTION : NetStat()
****************************************************
PROCEDURE NetStat()
Liste est une chaîne
Liste = GetExtendedTcpTable()
//Liste += [cr] + GetExtendedUdpTable()
RENVOYER Liste

****************************************************
* POUR LE TCP
****************************************************

// see : http://msdn.microsoft.com/en-us/library/aa365928%28VS.85%29.aspx
PROCEDURE GetExtendedTcpTable()
Res est un entier système = 0
Size est un entier système = 0
TcpTable est un tableau dynamique de 0 entiers sans signe sur 4 octets
NbEntry est un entier sans signe sur 4 octets
MibTcpRow est une MIB_TCPROW
ptr, Index sont des entiers
Liste est une chaîne = ""
// premier appel pour récupérer la taille du buffer
Res = API("Iphlpapi.dll","GetExtendedTcpTable", Null, &Size, True, AF_INET,
TCP_TABLE_BASIC_ALL, 0)
IF Res <> ERROR_INSUFFICIENT_BUFFER THEN RENVOYER ""
// dimensionne un buffer avec la bonne taille
Dimension(TcpTable, Size/4)
Res = API("Iphlpapi.dll","GetExtendedTcpTable", &TcpTable, &Size, True,
AF_INET, TCP_TABLE_BASIC_ALL, 0)
IF Res <> NO_ERROR THEN RENVOYER ""
// la première valeur correspond au nombre d'entrée
NbEntry = TcpTable[1]
IF EnModeTest() THEN TraceFin()
FOR ptr=1 _TO_ NbEntry
Index = 2 + ((ptr-1) * 5)
Transfer(&MibTcpRow, &TcpTable[Index], Dimension(MibTcpRow))
Liste += [CR] + "TCP" + TAB +...
inet_ntoa(MibTcpRow:LocalAddr) + ":" + inet_port(MibTcpRow:LocalPort) + TAB
+...
inet_ntoa(MibTcpRow:RemoteAddr) + ":" + inet_port(MibTcpRow:RemotePort) +
TAB +...
TcpState[MibTcpRow:State] + TAB + MibTcpRow:State
END
RENVOYER Liste

****************************************************
* L'adresse ip renvoyee est un entier sur 4 octets à l'envers
* si on à 127.0.0.1 on à en hexa 0100007f et non 7f000001
* soit 16777343 au lieu de 2130706433
****************************************************
FUNCTION inet_ntoa(pNumAddr)
AdresseIp est une chaîne = ""
AdresseIp = NumériqueVersChaîne(pNumAddr,"08X")
AdresseIp = ChaîneConstruit("%1.%2.%3.%4",HexToDec(AdresseIp[[7 sur 2]]),
HexToDec(AdresseIp[[5 sur 2]]), HexToDec(AdresseIp[[3 sur 2]]),
HexToDec(AdresseIp[[1 sur 2]]))
RENVOYER AdresseIp

****************************************************
* "A3" --> 163
* c'est un peu brutal mais bon cela fonctionne....
****************************************************
FUNCTION HexToDec(pOctet est une chaîne)
i, j est un entier = 0
IF "0" <= pOctet[[1]] <= "9" THEN
i = Val(pOctet[[1]])
ELSE
i = Asc(pOctet[[1]]) - Asc("A") + 10
END
j = i * 16
IF "0" <= pOctet[[2]] <= "9" THEN
i = Val(pOctet[[2]])
ELSE
i = Asc(pOctet[[2]]) - Asc("A") + 10
END
j += i
RENVOYER j

****************************************************
* Le numéro du port renvoyé est un entier sur 4 octets à l'envers
* si on à 21 (ftp) on à en hexa 0x51 au lieu de 0x15
****************************************************
PROCEDURE inet_port(pPort)
Port est une chaîne = NumériqueVersChaîne(pPort, "04X")
nPort est un entier = HexToDec(Port[[3 sur 2]])*256 + HexToDec(Port[[1 sur
2]])
RENVOYER nPort


"GUERVILLE" <webmaster@consulog.net> a écrit dans le message de news:
bbf62bfa246cbbd428f9be4411df8b5a@news.pcsoft...

bonjour,

Je cherche a savoir si un port (le 4900 en TCP) est ouvert ou non chez un
client. Il y a bien netstat, mais la reponse est trop compliquée.
avez vous une solution pour affichier Port 4900 TCP ouvert : OUI / NON

Merci
Posté le 01 avril 2010 - 20:11
Il va surement falloir qu'on viennent tous sur place pour analyser ton problème et te donner la solution ;)
Posté le 02 avril 2010 - 01:40
Oui, domage qu'il n'existe pas une fonction TestPort ...
Posté le 02 avril 2010 - 10:53
Comme promis , la suite pour l'UDP :

Supprimer // dans la fonction NetStat , ligne :
//Liste += [cr] + GetExtendedUdpTable()

**************************************
A rajouter dans les constantes
**************************************
UDP_TABLE_BASIC = 0
UDP_TABLE_OWNER_PID = 1
UDP_TABLE_OWNER_MODULE = 2

**************************************
A rajouter dans la déclaration de la collection
**************************************
MIB_UDPROW est une structure
LocalAddr est un entier système // The IPv4 address of the UDP endpoint on
the local computer.
// A value of zero indicates a UDP listener willing to accept datagrams for
// any IP interface associated with the local computer.
LocalPort est un entier système // The port number of the UDP endpoint on
the local computer.
// This member is stored in network byte order.
END

********************************************************************
// see : http://msdn.microsoft.com/en-us/library/aa365930%28v=VS.85%29.aspx
PROCEDURE GetExtendedUdpTable()
Res est un entier système = 0
Size est un entier système = 0
UdpTable est un tableau dynamique de 0 entiers sans signe sur 4 octets
NbEntry est un entier sans signe sur 4 octets
ptr, Index sont des entiers
MibUdpRow est une MIB_UDPROW
Liste est une chaîne = ""
// premier appel pour récupérer la taille du buffer
Res = API("Iphlpapi.dll","GetExtendedUdpTable", Null, &Size, True, AF_INET,
UDP_TABLE_BASIC, 0)
IF Res <> ERROR_INSUFFICIENT_BUFFER THEN RENVOYER ""
// dimensionne un buffer avec la bonne taille
Dimension(UdpTable, Size)
Res = API("Iphlpapi.dll","GetExtendedUdpTable", &UdpTable, &Size, True,
AF_INET, UDP_TABLE_BASIC, 0)
IF Res <> NO_ERROR THEN RENVOYER ""
NbEntry = UdpTable[1]
FOR ptr=1 _TO_ NbEntry
Index = 2 + ((ptr-1) * 2)
Transfer(&MibUdpRow, &UdpTable[Index], Dimension(MibUdpRow))
Liste += [CR] + "UDP" + TAB + inet_ntoa(MibUdpRow:LocalAddr) + ":" +
inet_port(MibUdpRow:LocalPort) + TAB +...
"*:*" + TAB + "" + TAB + ""
END
RENVOYER Liste
//---------------------- FIN ------------------------//


"Philippe Pasquali" <philippe.pasquali@guy-gaudefroy.com> a écrit dans le
message de news: 4bb4be47@news.pcsoft.fr...

bonjour
si joint du code testé sous xp pro qui est une écriture de la commande :
netstat -a -n
mais pour le moment il n'y a que le tcp (l'udp est en cours...) et j'ai
ajouté le code de l'état (ca mange pas de pain...)
J'ai mis ça dans une collection : procIP
Pour tester : Trace(NetStat())

nota : Il y a des déclarations inutiles mais je ferais la purge plus
tard...


****************************************
* DECLARATION DE LA COLLECTION procIP
****************************************
CONSTANT
AF_INET = 2
AF_INET6 = 10
//
TCP_TABLE_BASIC_LISTENER = 0 // A MIB_TCPTABLE table that contains all
listening (receiving only) TCP endpoints on the local computer is returned
to the caller.
TCP_TABLE_BASIC_CONNECTIONS = 1 // A MIB_TCPTABLE table that contains all
connected TCP endpoints on the local computer is returned to the caller.
TCP_TABLE_BASIC_ALL = 2 // A MIB_TCPTABLE table that contains all TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_LISTENER = 3 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID that contains all listening (receiving only) TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_CONNECTIONS = 4 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID that structure that contains all connected TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_PID_ALL = 5 // A MIB_TCPTABLE_OWNER_PID or
MIB_TCP6TABLE_OWNER_PID structure that contains all TCP endpoints on the
local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_LISTENER = 6 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all listening
(receiving
only) TCP endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_CONNECTIONS = 7 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all connected TCP
endpoints on the local computer is returned to the caller.
TCP_TABLE_OWNER_MODULE_ALL = 8 // A MIB_TCPTABLE_OWNER_MODULE or
MIB_TCP6TABLE_OWNER_MODULE structure that contains all TCP endpoints on
the
local computer is returned to the caller.
//
NO_ERROR = 0
ERROR_INSUFFICIENT_BUFFER = 0x7A
// ERROR_INVALID_PARAMETER =
// The state of the TCP connection.
MIB_TCP_STATE_CLOSED = 1 // The TCP connection is in the CLOSED state that
represents no connection state at all.
MIB_TCP_STATE_LISTEN = 2 // The TCP connection is in the LISTEN state
waiting for a connection request from any remote TCP and port.
MIB_TCP_STATE_SYN_SENT = 3 // The TCP connection is in the SYN-SENT state
waiting for a matching connection request after having sent a connection
request (SYN packet).
MIB_TCP_STATE_SYN_RCVD = 4 // The TCP connection is in the SYN-RECEIVED
state waiting for a confirming connection request acknowledgment after
having both received and sent a connection request (SYN packet).
MIB_TCP_STATE_ESTAB = 5 // The TCP connection is in the ESTABLISHED state
that represents an open connection, data received can be delivered to the
user. This is the normal state for the data transfer phase of the TCP
connection.
MIB_TCP_STATE_FIN_WAIT1 = 6 // The TCP connection is FIN-WAIT-1 state
waiting for a connection termination request from the remote TCP, or an
acknowledgment of the connection termination request previously sent.
MIB_TCP_STATE_FIN_WAIT2 = 7 // The TCP connection is FIN-WAIT-1 state
waiting for a connection termination request from the remote TCP.
MIB_TCP_STATE_CLOSE_WAIT= 8 // The TCP connection is in the CLOSE-WAIT
state
waiting for a connection termination request from the local user.
MIB_TCP_STATE_CLOSING = 9 // The TCP connection is in the CLOSING state
waiting for a connection termination request acknowledgment from the
remote
TCP.
MIB_TCP_STATE_LAST_ACK = 10 // The TCP connection is in the LAST-ACK state
waiting for an acknowledgment of the connection termination request
previously sent to the remote TCP (which includes an acknowledgment of its
connection termination request).
MIB_TCP_STATE_TIME_WAIT = 11 // The TCP connection is in the TIME-WAIT
state
waiting for enough time to pass to be sure the remote TCP received the
acknowledgment of its connection termination request.
MIB_TCP_STATE_DELETE_TCB= 12 // The TCP connection is in the delete TCB
state that represents the deletion of the Transmission Control Block
(TCB),
a data structure used to maintain information on each TCP entry.
END
MIB_TCPTABLE est une structure
NumEntries est un entier système // The number of entries in the table.
table est un entier système // A pointer to a table of TCP connections
implemented as an array of MIB_TCPROW structures.
END
MIB_TCPROW est une structure
State est un entier système // The state of the TCP connection
LocalAddr est un entier sans signe sur 4 octets // The local IPv4 address
for the TCP connection on the local computer. A value of zero indicates
the
listener can accept a connection on any interface.
LocalPort est un entier système // The local port number in network byte
order for the TCP connection on the local computer.
RemoteAddr est un entier sans signe sur 4 octets // The IPv4 address for
the
TCP connection on the remote computer. When the dwState member is
MIB_TCP_STATE_LISTEN, this value has no meaning.
RemotePort est un entier système // The remote port number in network byte
order for the TCP connection on the remote computer. When the dwState
member
is MIB_TCP_STATE_LISTEN, this member has no meaning.FIN
END
//--------------------
MIB_TCPTABLE_OWNER_PID est une structure
NumEntries est un entier système // The number of MIB_TCPROW_OWNER_PID
elements in the table.
table est un entier système // Array of MIB_TCPROW_OWNER_PID structures
returned by a call to GetExtendedTcpTable.
END
MIB_TCPROW_OWNER_PID est une structure
State est un entier système // The state of the TCP connection.
LocalAddr est un entier système // The local IPv4 address for the TCP
connection on the local computer. A value of zero indicates the listener
can
accept a connection on any interface.
LocalPort est un entier système // The local port number in network byte
order for the TCP connection on the local computer.
RemoteAddr est un entier système // The IPv4 address for the TCP
connection
on the remote computer. When the dwState member is MIB_TCP_STATE_LISTEN,
this value has no meaning.
RemotePort est un entier système // The remote port number in network byte
order for the TCP connection on the remote computer. When the dwState
member
is MIB_TCP_STATE_LISTEN, this member has no meaning.
OwningPid est un entier système // The PID of the process that issued a
context bind for this TCP connection.
END
//--------------------
MIB_TCP6TABLE_OWNER_PID est une structure
NumEntries est un entier système // The number of MIB_TCP6ROW_OWNER_PID
elements in the table.
table est un entier système // Array of MIB_TCP6ROW_OWNER_PID structures
returned by a call to GetExtendedTcpTable.
END
MIB_TCP6ROW_OWNER_PID est une structure
LocalAddr est un entier système // The IPv6 address for the local endpoint
of the TCP connection on the local computer. A value of zero indicates the
listener can accept a connection on any interface.
LocalScopeId est un entier système // The scope ID in network byte order
for
the local IPv6 address.
LocalPort est un entier système // The port number in network byte order
for
the local endpoint of the TCP connection on the local computer.
RemoteAddr est un entier système // The IPv6 address of the remote
endpoint
of the TCP connection on the remote computer. When the dwState member is
MIB_TCP_STATE_LISTEN, this value has no meaning.
RemoteScopeId est un entier système // The scope ID in network byte order
for the remote IPv6 address.
RemotePort est un entier système // The port number in network byte order
for the remote endpoint of the TCP connection on the remote computer.
State est un entier système // The state of the TCP connection.
OwningPid est un entier système // The PID of the local process that
issued
a context bind for this TCP connection.
END
in_addr est une structure
END
//---------------------------------------
TcpState est un tableau de 12 chaînes
TcpState[MIB_TCP_STATE_CLOSED] = "CLOSED"
TcpState[MIB_TCP_STATE_LISTEN] = "LISTEN"
TcpState[MIB_TCP_STATE_SYN_SENT] = "SYN-SENT"
TcpState[MIB_TCP_STATE_SYN_RCVD] = "SYN-RECEIVED"
TcpState[MIB_TCP_STATE_ESTAB] = "ESTABLISHED"
TcpState[MIB_TCP_STATE_FIN_WAIT1] = "FIN-WAIT-1"
TcpState[MIB_TCP_STATE_FIN_WAIT2] = "FIN-WAIT-2"
TcpState[MIB_TCP_STATE_CLOSE_WAIT] = "CLOSE-WAIT"
TcpState[MIB_TCP_STATE_CLOSING] = "CLOSING"
TcpState[MIB_TCP_STATE_LAST_ACK] = "LAST-ACK"
TcpState[MIB_TCP_STATE_TIME_WAIT] = "TIME-WAIT"
TcpState[MIB_TCP_STATE_DELETE_TCB] = "TCB"

****************************************************
* PRINCIPALE FONCTION : NetStat()
****************************************************
PROCEDURE NetStat()
Liste est une chaîne
Liste = GetExtendedTcpTable()
//Liste += [cr] + GetExtendedUdpTable()
RENVOYER Liste

****************************************************
* POUR LE TCP
****************************************************

// see : http://msdn.microsoft.com/en-us/library/aa365928%28VS.85%29.aspx
PROCEDURE GetExtendedTcpTable()
Res est un entier système = 0
Size est un entier système = 0
TcpTable est un tableau dynamique de 0 entiers sans signe sur 4 octets
NbEntry est un entier sans signe sur 4 octets
MibTcpRow est une MIB_TCPROW
ptr, Index sont des entiers
Liste est une chaîne = ""
// premier appel pour récupérer la taille du buffer
Res = API("Iphlpapi.dll","GetExtendedTcpTable", Null, &Size, True,
AF_INET,
TCP_TABLE_BASIC_ALL, 0)
IF Res <> ERROR_INSUFFICIENT_BUFFER THEN RENVOYER ""
// dimensionne un buffer avec la bonne taille
Dimension(TcpTable, Size/4)
Res = API("Iphlpapi.dll","GetExtendedTcpTable", &TcpTable, &Size, True,
AF_INET, TCP_TABLE_BASIC_ALL, 0)
IF Res <> NO_ERROR THEN RENVOYER ""
// la première valeur correspond au nombre d'entrée
NbEntry = TcpTable[1]
IF EnModeTest() THEN TraceFin()
FOR ptr=1 _TO_ NbEntry
Index = 2 + ((ptr-1) * 5)
Transfer(&MibTcpRow, &TcpTable[Index], Dimension(MibTcpRow))
Liste += [CR] + "TCP" + TAB +...
inet_ntoa(MibTcpRow:LocalAddr) + ":" + inet_port(MibTcpRow:LocalPort) +
TAB
+...
inet_ntoa(MibTcpRow:RemoteAddr) + ":" + inet_port(MibTcpRow:RemotePort) +
TAB +...
TcpState[MibTcpRow:State] + TAB + MibTcpRow:State
END
RENVOYER Liste

****************************************************
* L'adresse ip renvoyee est un entier sur 4 octets à l'envers
* si on à 127.0.0.1 on à en hexa 0100007f et non 7f000001
* soit 16777343 au lieu de 2130706433
****************************************************
FUNCTION inet_ntoa(pNumAddr)
AdresseIp est une chaîne = ""
AdresseIp = NumériqueVersChaîne(pNumAddr,"08X")
AdresseIp = ChaîneConstruit("%1.%2.%3.%4",HexToDec(AdresseIp[[7 sur 2]]),
HexToDec(AdresseIp[[5 sur 2]]), HexToDec(AdresseIp[[3 sur 2]]),
HexToDec(AdresseIp[[1 sur 2]]))
RENVOYER AdresseIp

****************************************************
* "A3" --> 163
* c'est un peu brutal mais bon cela fonctionne....
****************************************************
FUNCTION HexToDec(pOctet est une chaîne)
i, j est un entier = 0
IF "0" <= pOctet[[1]] <= "9" THEN
i = Val(pOctet[[1]])
ELSE
i = Asc(pOctet[[1]]) - Asc("A") + 10
END
j = i * 16
IF "0" <= pOctet[[2]] <= "9" THEN
i = Val(pOctet[[2]])
ELSE
i = Asc(pOctet[[2]]) - Asc("A") + 10
END
j += i
RENVOYER j

****************************************************
* Le numéro du port renvoyé est un entier sur 4 octets à l'envers
* si on à 21 (ftp) on à en hexa 0x51 au lieu de 0x15
****************************************************
PROCEDURE inet_port(pPort)
Port est une chaîne = NumériqueVersChaîne(pPort, "04X")
nPort est un entier = HexToDec(Port[[3 sur 2]])*256 + HexToDec(Port[[1 sur
2]])
RENVOYER nPort



"GUERVILLE" <webmaster@consulog.net> a écrit dans le message de news:
bbf62bfa246cbbd428f9be4411df8b5a@news.pcsoft...

bonjour,

Je cherche a savoir si un port (le 4900 en TCP) est ouvert ou non chez un
client. Il y a bien netstat, mais la reponse est trop compliquée.
avez vous une solution pour affichier Port 4900 TCP ouvert : OUI / NON

Merci


Posté le 02 avril 2010 - 11:51
Merci, je vais tester tout ca. Ca fait beaucoup de codes pour un simple test !