Reputation: 11
I am trying to nest string operations in ASP, but I am getting errors. I'm new to this, so I'm not sure where I'm going wrong. Any help would be great. Here's what I have:
Form Page:
<form method="post" action="ping.asp">
Subnet: <input type="text" name="subnet" value="XXX.XXX.XXX"><br>
First IP: <input type="text" name="first_ip" value="XXX"><br>
Last IP: <input type="text" name="last_ip" value="YYY"><br>
<input type="radio" name="OS" value="CISCO" /> IOS
<input type="radio" name="OS" value="CMD" /> Command Prompt <br>
<br>
<br>
<input type="submit" value="Submit">
</form>
ASP File:
<%
strHeading = "<h1>IOS AND COMMAND PROMPT RANGE PING BUILDER" & "</h1>"
strOS = Request.Form ("OS")
if strOS ="CISCO" then
strWrite = "<br>tclsh<br>for {set n <%=request.querystring("first_ip")%>} {$n<=<%=request.querystring("last_ip")%>} {incr n} {<br>if { [regexp "(!)" [exec "ping <%= Request.QueryString("subnet") %>.$n timeout 1 repeat 1" ]] } {<br>puts "<%=Request.QueryString("subnet")%>.$n"<br> } else { puts "<%=Request.QueryString("subnet")%>.$n **** failed ***" }<br> }<br><br>"
elseif strOS ="CMD" then
strWrite = "<br>for /L %z in (< % Request.QueryString("first_ip")% >,1,< % Request.QueryString("last_ip")% >) do @ping < % Request.QueryString("subnet"% >.%z -w 10 -n 1 | find "Reply"<br>"
else
strWrite = "Please select either IOS or Command Prompt."
End if
%>
<html>
<head>
<title>Range Ping Creator</title>
</head>
<body align=center>
<% Response.Write strHeading %>
<br>
<br>
<br>
<% Response.Write strWrite %>
<br>
<br>
<br>
</body>
</html>
It should output the following based on the radio selection. It works fine if i replace the strWrite text with plain text, but not with the operations. Any hints?
Proper output:
for /L %z in (XXX,1,YYY) do @ping XXX.XXX.XXX.%z -w 10 -n 1 | find "Reply"
tclsh
for {set n XXX} {$n<=YYY} {incr n} {
if { [regexp "(!)" [exec "ping XXX.XXX.XXX.$n timeout 1 repeat 1" ]] } {
puts "XXX.XXX.XXX.$n"
} else { puts "XXX.XXX.XXX.$n ** failed *" }
}
Upvotes: 1
Views: 88
Reputation: 3030
The way classic ASP works string concatenation is like this (it uses the ampersand to concatenate):
strWrite = myOS & " some string here " & request.querystring("some_ip") & " and then more stuff."
When you're in an executing block of code ( stuff between <% and %> it's all regular VBScript/ASP stuff, no more need to inline code (using <%= and %>)
<%
strWrite = myOS & " is an operating system using the IP: " & request.querystring("ip_address") & "!"
'do more stuff here
%>
<HTML>
<HEAD>
<TITLE><%=mystring_title_variable_here%></TITLE>
</HEAD>
<BODY>
Hey there, folks. This is what I know:
<P><%=strWrite%></P>
</BODY>
</HTML>
Gives an example of using them both ways.
Upvotes: 0