+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
Coding Thread, am i going mad? in Coding and Web Development; Originally Posted by PiqueABoo The file does not begin with a space, it begins with 0x00 which is not ASCII ...
  1. #16
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,525
    Thank Post
    106
    Thanked 89 Times in 75 Posts
    Blog Entries
    46
    Rep Power
    40

    Re: am i going mad?

    Quote Originally Posted by PiqueABoo
    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 :-)

  2. #17
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,525
    Thank Post
    106
    Thanked 89 Times in 75 Posts
    Blog Entries
    46
    Rep Power
    40

    Re: am i going mad?

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

    Code:
    @echo off
    :loop
    ping www.google.com -n 1 | find "reply from" /i > log.txt
    wget http://192.168.1.1/cgi-bin/webcm?get...odemstatus.htm --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
    Code:
    '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 nowrap class='tabdata'>(.*?)<\/td>",routerhtml)
    	'wscript.echo deletecrap	
    	deletecrap=replace(deletecrap,"<td nowrap class='tabdata'>"," ")
    	deletecrap=replace(deletecrap,"</td>","#")
    	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

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •