Solved

Want to ping and telnet from an asp.net datagrid on the client side

Posted on 2004-04-08
13
693 Views
Last Modified: 2012-08-14
Hello, i have a grid that contains multiple columns, one of which contains an ip address (for switches...).

I'd like to have one button that opens a window and pings the ip address and another that telnets to it.  I realize that this needs to happen on the client side and wonder if I need to use javascript or something along those lines?

I'm open to workarounds...  Would it be better to ping it from the server side and put the output into an html page and direct the user to it or something?  I have no idea what kind of workaround there might be for telnetting.

Any help would be very greatly appreciated!
0
Comment
Question by:MrDeveloper
13 Comments
 
LVL 28

Expert Comment

by:iboutchkine
ID: 10786732
I don't think that you can run exe on the client side due to the security settings. Maybe you can install an ActiveX on the client computer
0
 

Author Comment

by:MrDeveloper
ID: 10786756
I thought of a workaround for telnet:

telnet://www.yahoo.com

I can just do a response.redirect("telnet://" & Ipaddress) or something along those lines.  Ping doesn't seem to work from the browser though... I guess a hack would be to create a shell command like:

ping 10.1.1.1 > PingResults.txt

and try to response.redirect to that file on the server.  Definitely a hack, but I'm going to try that
0
 

Author Comment

by:MrDeveloper
ID: 10786883
Well, the ping seems to work pretty consistently (writing ping results to a text file, redirecting to it), but the telnet://IpAddress doesn't work - gives me a standard "The page cannot be displayed" and never redirects anywhere.  Any thoughts or other ideas to get that working?  I'm definitely still open to a better way to do the pinging too

Thanks!
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 22

Accepted Solution

by:
_TAD_ earned 500 total points
ID: 10786963


I'll tell you that doing both of those things are not possible through .Net (pinging from a client and opening a telnet session).

I can ping from the server, and then redirect the output to a variable.  That variable you can send to the web page and display the data.

Telnet is a whole different critter.  It is not possible to do telnet from .Net (server or client).  You'd have to create your own telnet app and use RAW socket connections to get the equivelant effect.
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10786992


Here's a link on how to do telnet from .Net (it's not easy)
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20815562.html

0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10787016


here's how you can ping from the server (using code-behind), store the results to a variable and then do something with the string


               
               Process myCmd = null;
               ProcessStartInfo qOptions = new ProcessStartInfo(@"cmd.exe", @"/K ping 127.0.0.1");
               qOptions.RedirectStandardOutput = true;  // set to "true" to enable logging
               qOptions.UseShellExecute = false;  // set to false to enable logging
               
               myCmd = Process.Start(qOptions);

               StreamReader str = myCmd.StandardOutput;
               Response.Write(str.ReadToEnd());
               
               myCmd.WaitForExit();
0
 

Author Comment

by:MrDeveloper
ID: 10791046
Hey Tad,

First of all, thanks very much for the ping code.  I used:

            Path = "c:\inetpub\wwwroot\PingResults.txt"  'on the server

            'capture the ip address in the row that is selected
            IpAddress = grd.SelectedItem.Cells(3).Text

            'write to a file
            PingCommand = "ping " & IpAddress & " > " & Path
            Shell(PingCommand, AppWinStyle.Hide)

            Response.Redirect(Path)

But i like yours much better...  So, using telnet://[ip address] will not work from a browser?  Man, you are not kidding - that class provided in the other article is complex!  I can't even tell if it's designed to allow an asp.net client browser to telnet to an ip or not.  

Thank you, i'm going to look for some kind of workaround for telnet...
0
 

Author Comment

by:MrDeveloper
ID: 10791328
I still can't understand why I can type telnet://ip into my browser address line and it will telnet to that, but if I do response.redirect("telnet://ip"), I get a page not found kind of thing.  
0
 

Author Comment

by:MrDeveloper
ID: 10792758
Hmm... found a way to make telnet work - <a href="telnet://www.yahoo.com">Telnet</a  

Works great...  Anybody know how to make a similar one for pinging?
0
 

Author Comment

by:MrDeveloper
ID: 10793208
Hey TAD, I get "StandardOut has not been redirected. " when I use your ping process code
0
 

Author Comment

by:MrDeveloper
ID: 10793498
Boy, what a hack this is, but it works...  I wrote a quick sp to return the data, then called it from my .net web form and pumped the output into a grid.  Both are posted below in case somebody else needs a way to do this and finds this question.  

Please give me some more detail on your ping solution TAD.  Your way is unquestionably better, but this hack will allow me to meet the deadline and I can update them later with a better fix.

Thanks


    Private Sub PopulateGrid()
        Dim cmd As SqlCommand, dr As SqlDataReader

        cmd = New SqlCommand("GetPingResults", Session("cn"))

        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.Add("@Ip", Session("Ip"))

        dr = cmd.ExecuteReader


        With grd
            .DataSource = dr
            .DataBind()
        End With


        dr.Close()


    End Sub


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetPingResults]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetPingResults]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE GetPingResults @Ip varchar(30)
AS

      
      DECLARE @strCmd VARCHAR(60)
      
      SELECT @strCmd = 'ping ' + @Ip
      
      EXEC Master..xp_cmdShell @strCmd


GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

0
 

Author Comment

by:MrDeveloper
ID: 10805720
I'm going to stick with my hack here, but TAD_, you comments were helpful and kind of what I ended up doing.  Thanks!
0
 

Expert Comment

by:digitalconvict
ID: 11020735
If it's a telnet component you're looking for, you could try:

http://www.whisperstream.com/software/commlib/

I dunno if they have any other components, but the telnet one they have is okay and seems to be free and not expire (always a bonus).
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question