Beh, fai così: crei un dataset, ti connetti al db e popoli il dataset.
Prima di proseguire sarebbe il caso di modificare il codice precedente in questo modo:
private bool CheckStatusPort(string Addr, string Port) {
string Addr = "192.168.0.1";
int Port = 80;
TcpClient Sock = new TcpClient();
try {
Sock.Connect(Addr, Port);
Sock.Close();
return true;
} catch (Exception E) {
return false;
}
Sock = null;
}
Così, richiamando CheckStatusPort riceverai un valore booleano a seconda dell'apertura o meno della porta.
Ecco un esempio di come proseguire:
string dbAddr, dbPort;
DataSet ds = ... // Popolo il dataset
for (int i=0; i < ds.Tables[0].Rows.Count; i++) {
dbAddr = (string) ds.Tables[0].Rows[i]["Addr"];
dbPort = (string) ds.Tables[0].Rows[i]["Port"];
if ( CheckStatusPort(dbAdrr, dbPort) )
Response.Write(dbAddr + ": " + dbPort + " - Porta aperta");
else
Response.Write(dbAddr + ": " + dbPort + " - Porta utilizzata");
}
Spero di essermi fatto capire![]()