I have been accessing a website and entering 3 parameters and an Authorization to get access to data. When processed, the data appears in a Responds Window on the website, and I manually select all and copy it to a text file. The Authorization Key is good for a day, and I just need to update the 3 parameters each time when I make a request.
I have to repeat this process for about 50+ times.
I have tried using this sample code from someone on this website over 1 year ago, and I have no errors, and it doesn't seems to connect.
I am perfectly happy trying to get it working by manually entering the authorization key code for now. This takes most of the coding out.
Sub Test()
Dim sUrl As String, sAuth As String
sUrl = "https://cl.nnn.nnnn.com/api/tracking/game/play?gameId=2017121601&gamekey=57444&playId=51"
sAuth = "NGS AKIAIX2XXXXXXXXXPOTKDQ:XXXXXXXXXXXkfmT7enl6I="
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", sUrl, False
.SetRequestHeader "Authorization", "Basic " & sAuth
.Send
Debug.Print .ResponseText
Debug.Print .GetAllResponseHeaders
End With
End Sub
How I can get the amount of bytes that had been sent via winsock through TCP connection?
It's simply the return value of send().
For more information about send or Winsock in general look here:
http://msdn.microsoft.com/library/windows/desktop/ms740149%28v=vs.85%29.aspx
Question:
Do you want to know how many bytes were sent with a single .SendData() call?
Or do you want to know how many bytes were sent throughout the lifetime of your program running?
Question 1.
Several options:
You can just calculate the length of the data you're sending. It's very easy if it's a string: Len(DataBeingSent) will give you the number of bytes. Tell us what you're sending or show us some code.
You can keep track using a form-scope variable, but this is a pretty poor way to do it in my opinion unless it is for question #2 above.
Option Explicit
Private lonBytesSent As Long
Private Sub Winsock1_Connect()
Dim strData As String
strData = "This example uses a string but will work with any type being sent."
' Reset the number of bytes sent from any previous packets.
lonBytesSent = 0
Winsock1.SendData strData
End Sub
Private Sub Winsock1_SendComplete()
MsgBox CStr(lonBytesSent) & " byte(s) sent on last transmission.", vbInformation
End Sub
Private Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
lonBytesSent = lonBytesSent + bytesSent
End Sub
Question 2.
If this is the case, the above code will work just remove the lonBytesSent = 0 before the .SendData() call. You may want to use a bigger data type than a Long if you will be sending a lot of data.
I am trying to solve a problem with a site written in classic ASP with a SQL Server 2000 database.
Every few days the site seems to go down. There is no response from the website when you try to visit it. The loading indicator in your browser will spin round and the page just stays blank.
When I run sp_who2 after the site has gone down there's always a process that has taken up a large amount of CPU time. This process will be blocking all the other processes in the database.
I can get the site working again by killing this process.
I can't work out what's going on. When I look to see the stored procedure that this process ran before it locked up there's nothing wrong with it. The page that runs this stored procedure closes all the connection objects.
Any ideas of what could be causing this deadlock, or how I can stop it from happening?
Not sure if this is the issue, but it could be that not all recordsets and connection are always closed... When we had similar issues in the past we ended up with the following routine.. (Note that this is just a snippet showing one recordset closure, the real procedure actually goes over 15 different recordsets to see if they need to be closed..).
The modCloseObjects() prodedure is then always called at the end of the page, before a redirect, inside error handling and so one...
' subroutine will close and set the objects to Nothing. '
' Close Recordsets and then the Connection '
sub modCloseObjects()
'Close the record sets one by one '
If ucase(TypeName(oRS)) = "RECORDSET" then
if oRS.state <> adStateClosed then
oRS.close
Set oRS = Nothing
end if
end if
' if you have other recordSet objects, add them to the rourtine here: '
' Close the connection '
If ucase(TypeName(objConn)) = "CONNECTION" then
if objConn.state <> adStateClosed then
objConn.close
Set objConn = Nothing
end if
end if
end sub
If you don't have adovbs.inc , you'll need the following constant too:
Const adStateClosed = &H00000000
I have a website where people send each other messages
Recently I noticed that sometimes the same message is sent more than once
For example, a message is sent four times within three seconds or twice within a second
I do not understand how this could happen, once the user clicks on the button that sends the message
So all the window switches and a message showup saying "the mail is sent successfully."
I checked that if the user refreshes the page after it sends a message, then really the message is sent again.
But I do not think that's the case, becouse the message is sent twice within one second.
I am writing in vb.net and using mysql data base.
Maybe it's related to the queue for the db, i do not know.
I need to know where to look
Hope for your help
Here's the code:
Function calls:
Call GlobalFunction.update_mailbox_table(user_id, receiverId, txtMessage.Text, private_picture)
the insert function
Public Shared Sub update_mailbox_table(ByVal user_id As Integer, ByVal receiverId As Integer, ByVal message As String, ByVal privatePicture As Integer)
' update mailbox table
Dim connString As String = ConfigurationManager.ConnectionStrings("mysql_ConnString").ConnectionString
Using mysqlconn As New MySqlConnection(connString)
Dim sqlCommand As String = "INSERT INTO mailbox_table (FromId,Message,ToId,SendingDate,MsgStatus,PrivatePicture) VALUES (#FromId,#Message,#ToId,#SendingDate,#MsgStatus,#PrivatePicture)"
Dim mysqlcmd As New MySqlCommand(sqlCommand, mysqlconn)
Try
mysqlconn.Open()
mysqlcmd.Parameters.AddWithValue("#FromId", user_id)
mysqlcmd.Parameters.AddWithValue("#Message", message)
mysqlcmd.Parameters.AddWithValue("#ToId", receiverId)
mysqlcmd.Parameters.AddWithValue("#SendingDate", Date.Now)
mysqlcmd.Parameters.AddWithValue("#MsgStatus", 0)
mysqlcmd.Parameters.AddWithValue("#PrivatePicture", privatePicture)
mysqlcmd.ExecuteNonQuery()
Catch ex As Exception
sendToLog(ex, "problem to update mailbox table")
End Try
End Using
End Sub
The problem is not in the database code, my psychic debug power tells me that your user double of quad clicks on your submit button.
Are you using Javascript to show the message client side (i.e. actually before the message has been sent), or are you showing the message when the page reloads after sending the message?
If you are not hiding the button using client script, the user can easily click several times before the page reloads. Each click will send a request to the server, but the browser only shows the response for the last click.
I have a site running Classic-ASP and on the login page I would like to delay the response to a failed login attempt (by like 10 seconds) to help prevent brute force attacks on accounts.
Quick google searches show some hacks using SQL server queries that seem hack-tastic.
Is there a good way to do this in classic asp?
I am not going to answer your specific question, as many have already done so, but there are far better ways of preventing brute force attacks.
For instance:
Why not lock a specific session or IP address out after say 5 (being generous here) failed login attempts? You could lock it out for say 10 minutes. You could even write a "401 Unauthorized" HTTP status and then simply end the response with Response.End.
In a similar fashion, but not even linked to failed logins, you could block requests for the login page more than X times in Y seconds for a specific IP, UserAgent and other client features - ensuring kind of a 'unique' client.
Ignore IP address (it is easily spoofed and can be a proxy server IP), and simply detect the automation of the login attempt. X number of failed logins within Y seconds for a specific username/email address, block it for that username for a set period of time, and end the response.
Just saying there are other options than putting unnecessary load on your server by locking some resources and waiting.
Obviously, doing this at the hardware layer - firewalls etc. would be the preferred option.
There is another approach, but keep in mind the aforementioned caveats about unessecarily consumed resources. Here is an approach though
Sub DelayResponse(numberOfseconds)
Dim WshShell
Set WshShell=Server.CreateObject("WScript.Shell")
WshShell.Run "waitfor /T " & numberOfSecond & "SignalThatWontHappen", , True
End Sub
There is the WScript.Sleep method for general purpose VBScript, however, this won't work in the context of ASP.
There are a number of other mechanisms you can use to achieve this, however, they're all effectively "workarounds" as there's no built-in way to cleanly cause an ASP page (running VBScript) to pause itself.
See here:
How do I make my ASP page pause or 'sleep'?
To specifically answer your question of:
Is there a good way to do this in
classic asp?
No. There's no good way to do this, and there's only the "hack-tastic" hacks that can be used, however they bring with them all sorts of side-effects and caveats. (See the last part of the "How do I make my ASP page pause or 'sleep'?" link for a specific memory eating, page faulting nasty side-effect.)
You can use :
<html>
<head>
<title>Sleep</title>
</head>
<body>
<%
function Sleep(seconds)
set oShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c timeout " & seconds & " /nobreak"
oShell.Run cmd,0,1
End function
Sleep(5)
response.write("End")
%>
</body>
</html>
There is no simple way to do so in pure ASP.
Either SQL WAITFOR, or create simple ActiveX component in VB (or anything) that sleeps.
Note that this will increase load on the server. Sleeping requests keep memory and connections consumed for nothing.
<%
set shell = CreateObject("WScript.Shell")
t1 = timer()
sleep(5)
t2 = timer()
response.write "waited "& t2-t1 &" secs"
function sleep(seconds)
if seconds>=1 then shell.popup "pausing",seconds,"pause",64
end function
%>
Other approach to avoid brute force attacks without using IP restrictions is to offer a captcha after the second fail attempt for the same user. This is the way Google do it.
There is the Response.Buffer option that you can use to tell it to delay returning the response until the page has completed processing, so you could perhaps combine that with some kind of timeout in the script, but it would not be especially elegant especially as VBScript doesn't really offer you a way of asking threads to sleep so you can end up thrashing the CPU.
Maybe better to use a server-side session and javascript on the client, so the client delays the request and the server will only send the response after the expected delay is over. That should provide some server-side safeguards and be useable for users who aren't trying to mess around with your system...
I'm using this:
function sleep(scs)
Dim lo_wsh, ls_cmd
Set lo_wsh = CreateObject( "WScript.Shell" )
ls_cmd = "%COMSPEC% /c ping -n " & 1 + scs & " 127.0.0.1>nul"
lo_wsh.Run ls_cmd, 0, True
End Function
sleep(5) 'wait for 5 seconds
Bye :-)
For those using MySQL, you can do the following :
Sub SleepMysql(n)
'Define Query
Dim SqlStr : SqlStr = "DO SLEEP(" & n & ")"
'Run Query
Dim rsTemp : Set rsTemp = YourDatabaseConnection.Execute(SqlStr)
'Release resources
Set rsTemp = Nothing
End Sub 'SleepMysql
Of all of the ideas - I liked Dercsár's answer - here's my implementation of a wait that I found works well. - requires your application to have access to a SQL server:
<%
' ASP Script to example to wait
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConnString ' your connection to sql server here...
Response.write("Waiting for 15 seconds...." & now() & "<BR>")
Call subWaitTime("00:00:15")
' Wait 15 seconds
Response.write("ok - Done" & now() & "<BR>")
conn.close
set conn = nothing
'---- Utility sub to wait
Sub subWaitTime(sTime)
' Call subWaitTime with number of Hours:Minutes:Seconds to delay
sqlWaitTime = "WAITFOR DELAY " & fnSqlStr(sTime)
conn.Execute(sqlWaitTime) '
End Sub
%>
In response to the “delay the response” part of your question:
dim SecondsToWait : SecondsToWait = 4
dim StartTime : StartTime = Time()
Do Until
DateDiff("s", StartTime, Time(), 0, 0) > SecondsToWait
Loop
Pure Classic ASP without SQL and WScript Shell, but for debug delay purposes only. This is a snippet for testing (very helupful), but it does not address the “good way” part of your question
This answer for the sake of completeness and for people looking for (debug) delays. Failed login attempts should not be handled like this.
Another way you can delay asp response by using this code.
Sub MyDelay(NumberOfSeconds)
Dim DateTimeResume
DateTimeResume= DateAdd("s", NumberOfSeconds, Now())
Do Until (Now() > DateTimeResume)
Loop
End Sub
Call this function by using this code.
Call MyDelay(5)
Just redirect to a randomly named large image that takes the desired amount of seconds to load.