Ricky1986

Random url to script.

25 posts in this topic

Hello, I'm new to the whole Autoit scene and picking stuff up as I go.

I have a script that I found and would like to modify it to work but need help in doing so, so I can learn from it.

basically want to add a random URL to the referrer via a text file.

 

 

 

referer.au3

Share this post


Link to post
Share on other sites



Learn:

 

_FileReadToArray

https://www.autoitscript.com/autoit3/docs/libfunctions/_FileReadToArray.htm

 

Random

https://www.autoitscript.com/autoit3/docs/functions/Random.htm

 

UBound

https://www.autoitscript.com/autoit3/docs/functions/UBound.htm

 

Then read over this.

 

Global $Referrer
Local $ReferrerFile = "Referrer.txt"
Local $ReferrerExists = FileExists($ReferrerFile)
If $ReferrerExists Then
    _FileReadToArray($ReferrerFile, $Referrer, 0, "")
Else
    MsgBox(0, "Referrer - Setup Error", "The file Referrer.txt doesn't exist.")
    Exit
EndIf
If UBound($Referrer) = 0 Then
    MsgBox(0, "Referrer - Setup Error", "The file Referrer.txt is empty.")
    Exit
EndIf

Local $oIE = _IECreateEmbedded()

Local $hoIE = GUICtrlCreateObj($oIE, 8, 8, 500, 500)

$oIE.Navigate2("https://www.whatismyreferer.com/", Default, Default, Default, 'User-Agent: CustomBrowser' & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])

GUICtrlDelete($hoIE)

 

Everything you need is in that code.

 

Read it understand it and reuse it.

 

 

 

Share this post


Link to post
Share on other sites

Thanks for the reply fring1956 that's exactly what I need 

Share this post


Link to post
Share on other sites

So I have read up on them and will need to put them into practice.

I added the #includes and believe I  am right in doing so.

but still getting an error.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Referrer
Local $ReferrerFile = "referrer.txt"
Local $ReferrerExists = FileExists($ReferrerFile)
If $ReferrerExists Then
    _FileReadToArray($ReferrerFile, $Referrer, 0, "")
Else
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt doesn't exist.")
    Exit
EndIf
If UBound($Referrer) = 0 Then
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt is empty.")
    Exit
EndIf

Local $oIE = _IECreateEmbedded()
Local $hoIE = GUICtrlCreateObj($oIE, 8, 8, 500, 500)

$oIE.Navigate2("https://www.whatismyreferer.com/", Default, Default, Default, 'User-Agent: CustomBrowser' & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])

GUICtrlDelete($hoIE)

$oIE.Navigate("https://www.whatismyreferer.com/", Default, Default, Default, 'User-Agent: CustomBrowser' & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])
$oIE^ ERROR

So i know the issue ls to do with this line but cant see why.

Also with text colour _IECreateEmbeded is grey and not blue on my ide same with $oIE.Navigate2

Share this post


Link to post
Share on other sites
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Referrer
Local $ReferrerFile = "referrer.txt"
Local $ReferrerExists = FileExists($ReferrerFile)
If $ReferrerExists Then
    _FileReadToArray($ReferrerFile, $Referrer, 0, "")
Else
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt doesn't exist.")
    Exit
EndIf
If UBound($Referrer) = 0 Then
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt is empty.")
    Exit
EndIf

Local $oIE = _IECreate()
Local $hoIE = GUICtrlCreateObj($oIE, 8, 8, 500, 500)

$oIE.Navigate2("https://www.whatismyreferer.com/", Default, Default, Default, 'User-Agent: CustomBrowser' & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])

GUICtrlDelete($hoIE)

Problem solved this is my code now and seems to be working fine.

Share this post


Link to post
Share on other sites

@Ricky1986 - Code looks good, just wanted to add a couple of notes:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $Referrer
Global $ReferrerFile = @ScriptDir & "\referrer.txt"
;~ No reason to have $ReferrerExists as a variable as it's only used once
;~ Local $ReferrerExists = FileExists($ReferrerFile)
If FileExists($ReferrerFile) Then
    _FileReadToArray($ReferrerFile, $Referrer, 0)
    ;~ Use @Error to determine result of _FileReadToArray
    If @error Then
        MsgBox(0, "Referrer - Setup Error", "The file referrer.txt is empty.")
        Exit
    EndIf
Else
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt doesn't exist.")
    Exit
EndIf

Local $oIE = _IECreate()
;~ GuiCtrlCreateObject is only required if using _IECreateEmbedded
;~ Local $hoIE = GUICtrlCreateObj($oIE, 8, 8, 500, 500)
$oIE.Navigate2("https://www.whatismyreferer.com/", Default, Default, Default, 'User-Agent: CustomBrowser' & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])

;~ GUICtrlDelete($hoIE)

 

Share this post


Link to post
Share on other sites

Thanks, Subz I will edit it I've been playing with it further and have broken it if you don't mind looking at it so I can understand where I've gone wrong.

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $UserAgent
Global $Referrer
Local $UserAgentFile = "UserAgent.txt"
Local $ReferrerFile = "referrer.txt"
Local $UserAgentExists = FileExists($UserAgentFile)
Local $ReferrerExists = FileExists($ReferrerFile)

If $UserAgentExists Then
   _FileReadToArray($UserAgentFile, $UserAgent, 0, "")
Else
   MsgBox(0, "UserAgent - Setup Error", "The File UserAgent.txt doesn't exist.")
   Exit
EndIf
If UBound($UserAgent) = 0 Then
   MsgBox(0, "UserAgent - Setup Error", "The file UserAgent.txt doesn't exist.")
   Exit
   EndIf
If $ReferrerExists Then
    _FileReadToArray($ReferrerFile, $Referrer, 0, "")
Else
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt doesn't exist.")
    Exit
EndIf
If UBound($Referrer) = 0 Then
    MsgBox(0, "Referrer - Setup Error", "The file referrer.txt is empty.")
    Exit
EndIf

Local $oIE = _IECreate()
Local $hoIE = GUICtrlCreateObj($oIE, 8, 8, 500, 500)

$oIE.Navigate2("http://www.whoishostingthis.com/tools/user-agent/", Default, Default, Default, 'User-Agent: ' & $UserAgent[Random(0, UBound($UserAgent)] - 1,1) & @CRLF & 'Referer: ' & $Referrer[Random(0, UBound($Referrer) - 1, 1)])

GUICtrlDelete($hoIE)

I'm literally just writing and running it best way to learn just need help pick out the errors so I can see my mistakes. 

Share this post


Link to post
Share on other sites

Do you have the UserAgentList.txt and Referrer.txt that I can use to test?

Share this post


Link to post
Share on other sites

#11 ·  Posted

Can you try this:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $aUserAgent, $aReferrer
Local $sUserAgentFile = "UserAgent.txt"
Local $sReferrerFile = "referrer.txt"
_FileListArray('UserAgent', $sUserAgentFile, $aUserAgent)
_FileListArray('Referrer', $sReferrerFile, $aReferrer)

Global $oIE = _IECreate()
    $oIE.Navigate2("http://www.whoishostingthis.com/tools/user-agent/", Default, Default, Default, 'User-Agent: ' & $aUserAgent[Random(0, UBound($aUserAgent) - 1, 1)] & @CRLF & 'Referer: ' & $aReferrer[Random(0, UBound($aReferrer) - 1, 1)])

Func _FileListArray($sTitle, $sFileName, ByRef $aArray)
    If FileExists($sFileName) Then
        _FileReadToArray($sFileName, $aArray, 0, "")
        If @error Then
            MsgBox(0, $sTitle & " - Setup Error", "The file " & $sFileName & " is empty.")
            Exit
        EndIf
    Else
        MsgBox(0, $sTitle & " - Setup Error", "The File " & $sFileName & " doesn't exist.")
        Exit
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

Thanks for the quick edit, how did you learn it I need to read further into it?

Share this post


Link to post
Share on other sites

#13 ·  Posted

The forums and the helpfile mostly, I found it to be one of the easiest languages to learn, happy learning :) 

Share this post


Link to post
Share on other sites

#14 ·  Posted

I thought I'd try and alter it to give me a random URL does this work on the same principle or is it different?

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $aUserAgent, $aReferrer, $aURLList
Local $sUserAgentFile = "UserAgent.txt"
Local $sReferrerFile = "referrer.txt"
Local $sURLListFile = "URLList.txt"

_FileListArray('UserAgent', $sUserAgentFile, $aUserAgent)
_FileListArray('Referrer', $sReferrerFile, $aReferrer)
_FileListArray('URLList', $sURLListFile, $aURLList)

Global $oIE = _IECreate()
    $oIE.Navigate2('url: ' & $aURLList[Random(0, UBound($aURLList) -1, 1)] Default, Default, Default, 'User-Agent: ' & $aUserAgent[Random(0, UBound($aUserAgent) - 1, 1)] & @CRLF & 'Referer: ' & $aReferrer[Random(0, UBound($aReferrer) - 1, 1)])

Func _FileListArray($sTitle, $sFileName, ByRef $aArray)
    If FileExists($sFileName) Then
        _FileReadToArray($sFileName, $aArray, 0, "")
        If @error Then
            MsgBox(0, $sTitle & " - Setup Error", "The file " & $sFileName & " is empty.")
            Exit
        EndIf
    Else
        MsgBox(0, $sTitle & " - Setup Error", "The File " & $sFileName & " doesn't exist.")
        Exit
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

18 minutes ago, Subz said:

The forums and the helpfile mostly, I found it to be one of the easiest languages to learn, happy learning :) 

Thanks it seems to be a relatively easy language it's just getting my head around what does what and how to string them together 

Share this post


Link to post
Share on other sites

#16 ·  Posted

Yes that looks correct basically the _FileListArray function just cuts down on rewriting the same code, i.e. Check the file exists, read the file to array and the error msgboxes.

Share this post


Link to post
Share on other sites

#17 ·  Posted

Yeah, thats what I thought but I'm getting a blank web browser no URL is getting pulled. 

Share this post


Link to post
Share on other sites

#18 ·  Posted

I'm not sure why but you have .Navigate2('url: ' & you need to remove the 'url: ' & for it to work correctly

Share this post


Link to post
Share on other sites

#19 ·  Posted

Ricky1986,

The one thing that you are missing is clearing the cookies.

Creating multiple visits with AutoIt will be fairly obvious to whoever your sending these visits at if you have the same cookies.

Theres a few options for doing this:

$cookieFolder = RegRead ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Cookies")

MsgBox(0, "The cookies are here: ", $cookieFolder)

FileDelete ($cookieFolder & "\*.txt")

You can dispose of the control and delete them manually

Or you could 

RunWait("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351")

Ask windows to delete the cookies

Or probably even easier you can

;_IEDocGetObj
;https://www.autoitscript.com/autoit3/docs/libfunctions/_IEDocGetObj.htm

$sCookie = "name=richard;password=tehbstpass"

$oIE = _IECreate("http://www.example.com")

$oDocObj = _IEDocGetObj($oIE)

$oDocObj.cookie = $sCookie

Either way if your using the script to increase hits on a website you need:

Random user agent (see attached)

Random proxy

Clean cookies

 

 

UserAgent.txt

Share this post


Link to post
Share on other sites

#20 ·  Posted

@RichardHawkesford,

Why did you created a second account in our forums?
I will merge the 2 accounts and please stick to the original account.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now