Jump to content

Recommended Posts

Posted

got a script that retrieves router stats. need to modify it for a dlink router.

attached file is file retrieved off router.

 

the old script reads the whole file into a string.

 

modded script refuses to do anything with said string. can't even echo it

even test script wont. dont understand whats going on /cry

 

routerpage="modemstatus.htm"

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
set router = fso.opentextfile("e:\dlink\" & routerpage, ForReading)

routerhtml=router.ReadAll

wscript.echo len(routerhtml)

wscript.echo routerhtml

 

produces the output 3064 from the len but thats it. please help :(

Posted

hmm thats very strange.

 

that could be a problem cos thats how it comes off the router using wget.

it doesnt seem to want to ltrim either....

Posted
Have you tried opening the html file in notepad? I get the "This file is not a valid text file. It may be a binary file. Convert any NULL terminators to spaces and load anyway?" message so it must be the way it's either sent by the web server or the way wget wgot it.
Posted

it works for me ok in notepad. i can see the "space"

the only thing im doing different in this wget from the other working script(different router) is renaming the file because on the router its called

webcm?getpage=../html/status/modemstatus.htm which vbscript doesnt like either.

 

supposing its not really a space. any thoughts on how i can get rid of it?

 

i tried c:\>type modemstatus.htm > newmodemstatus.htm but it didnt make any difference.

Posted
When I tested it, I could loop through a line at a time using Do Until router.AtEndOfStream ... router.readline and it was OK. I presume you're looking for specific information from this file, so you could take this approach and just search a line at a time.
Posted

i havent got time to learn perl :p

 

there's more than one thing in there im after so im using regular expressions to locate several rows of information in the whole file. this kind of thing works well with webpages and tables. i've got a suggestion of using mid off another forum to extract all the string except the "space" if i can't get another to work the other option i have is telnet to the router and get it that way.

Posted
The format of that file is screwing up the opening of it using scripting. Have you considered using AutoIt to create an automated telnet type app? Something similar to this perhaps.
Posted

The file does not begin with a space, it begins with 0x00 which is not ASCII text and is a string terminator in most languages.

 

If you can't persuade whatever not to put that on the front, can you sanitise the file before you read it e.g. with the sysinternals strings util:

 

strings -a -q modemstatus.htm > fixedstatus.htm

 

Fixedstatus.htm will definitely be ASCII.

Posted
Can you not get anything from SNMP? Recent updates to my bog standard Dlink APs has added that functionality. Might be worth checking out.
Posted
One byte to get rid of and: Rewrite in PERL, never mind your VBS go and read a JScript thread, rewrite to use SNMP, go look at DOM. You lot should become a development team at RM ;b
Posted
The file does not begin with a space, it begins with 0x00 which is not ASCII text and is a string terminator in most languages.

 

If you can't persuade whatever not to put that on the front, can you sanitise the file before you read it e.g. with the sysinternals strings util:

 

strings -a -q modemstatus.htm > fixedstatus.htm

 

Fixedstatus.htm will definitely be ASCII.

 

woohoo that works. exactly what i was looking for. was starting asking people to make me one lol. thanks muchly :-)

Posted

woohoo got script modded and working; incase anyone is interested:

 

@echo off
:loop
ping [url]www.google.com[/url] -n 1 | find "reply from" /i > log.txt
wget [url]http://192.168.1.1/cgi-bin/webcm?getpage=../html/status/modemstatus.htm[/url] --no-proxy --output-document=modemstatus.htm

strings -a -q modemstatus.htm > fixedstatus.htm

echo go script:
cscript getinfo.vbs 
del modemstatus.htm

del fixedstatus.htm
echo waiting...
start /w wait 60
goto loop

 

'on error resume next
routerpage="fixedstatus.htm"

Const ForReading = 1, ForWriting = 2, ForAppending = 8

function findexp(exppattern,string)
dim objRegExp
set objRegExp = New RegExp
objRegExp.Pattern = exppattern
 	objRegExp.IgnoreCase = True
ObjRegExp.Global = True

set objMatches = objRegExp.Execute(string)

dim itemx,htmlstr2
	' Show all the matching HTML:
For Each Itemx in objMatches
 		htmlstr2=htmlstr2 & Itemx.Value  
Next
findexp=htmlstr2
end function

Set fso = CreateObject("Scripting.FileSystemObject")
set MyFile = fso.OpenTextFile("e:\dlink\log.txt", ForReading)
set router = fso.opentextfile("e:\dlink\" & routerpage, ForReading)
pingreply = MyFile.Readline
routerhtml=   router.Readall


router.close
myfile.close
'wscript.echo pingreply

if  (instr(1,pingreply,"ms",1)> 0)  then 
 ' connection is up
 
 pingarray=split(pingreply," ")
 ping_time_temp=split(pingarray(4),"=")
 ping_time=ping_time_temp(1)
 
 
 
 result= "UP!," & date & "," & time & "," & ping_time & ","
 
 else
 ' connection is down
 result= "DOWN!," & date & "," & time & ",,"  
 
 
end if  
 
 'so lets see about the router page
 'wscript.echo ">" & routerhtml
 'find matches


deletecrap = findexp("(.*?)<\/td>",routerhtml)
'wscript.echo deletecrap	
deletecrap=replace(deletecrap,""," ")
deletecrap=replace(deletecrap,"","#")
deletecrap=replace(deletecrap,"","")
deletecrap=replace(deletecrap,"(Kbps)","")

'wscript.echo deletecrap

crazyarray=split(deletecrap,"#")
for i = 0 to ubound(crazyarray)
	'wscript.echo (i & ": " & crazyarray(i))
	crazyarray(i)=trim(crazyarray(i))
next
' #1 upstream rate
' #3 downstream rate
' #5 US margin
' #7 ds margin
' #11 LOS errors
' #13 DS attenuatuation
' #15 US attenuation
' #17 path mode


header="Status,date,time,ping,"
header=header & "UP Sync,Down Sync,US Margin,DS Margin,LOS errors,DS Attenuation,US Attenuation,Path mode"


 result = result & crazyarray(1) & "," &  crazyarray(3) & "," & crazyarray(5) & "," & crazyarray(7) & "," 
    result = result & crazyarray(11) & "," &  crazyarray(13) & "," & crazyarray(15) & "," & crazyarray(17) 


    
    If (fso.FileExists("e:\dlink\results.csv"))Then
     	set outputfile=fso.OpenTextFile("e:\dlink\results.csv", ForAppending, True)   	
    else
       set outputfile=fso.OpenTextFile("e:\dlink\results.csv", ForWriting, True)
       outputfile.writeline header
    end if   
    
    outputfile.writeline result	
    outputfile.close
    
    wscript.echo result

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



×
×
  • Create New...