我用小区宽带上网,每次都得从WEB登录才能上网,谁能帮忙写个程序,实现自动WEB登录。
下面是登录页面的HTML代码,其中hexMD5()中的数值是可变的,不可预知的:
<html>
<head>
    <title>Login</title>
</head><body>    <form name="login" action="http://10.56.0.1/login" method="post" onSubmit="return doLogin()">
        <input name="username" type="text" value="username"/>
        <input name="password" type="password" value="password"/>
        <input type="submit" value="确定" />
    </form>    <script type="text/javascript" src="./md5.js"></script>
    <script type="text/javascript">
        function doLogin() {
            document.login.password.value = hexMD5('\330' + document.login.password.value + '\226\211\202\022\277\305\133\227\337\152\146\053\313\210\132\354');
            document.login.submit();
            return false;
        }
    </script></body>
</html>
我想实现类似下面JS的功能,要在后台运行,不显示IE窗口。
var ie = new ActiveXObject("InternetExplorer.Application");ie.navigate("http://10.56.0.1");
while(ie.busy){WScript.sleep(100);}var document = ie.document;
var window = document.parentWindow;
var form = document.forms[0];form.username.value = "username";
form.password.value = "password";form.elements[2].click(); 

解决方案 »

  1.   

    这个很简单,不用任何JS,直接写几行JAVA代码,请求http://10.56.0.1/login这个URL就可以了,在JAVA程序里,请求前要传入你的用户名和密码参数就OK了。
    差不多10行代码就搞定了,
    写好JAVA代码后,打个可执行的jar包,放在你桌面,上网前运行下就可以了。
    或者放在系统启动项里,OS启动了就自动可以上网了。
      

  2.   

    #1可能没有注意到document.login.password.value = hexMD5('\330' + doc...你还得解析到这一行中的内容.
    另外, 用GET还不一定可以, 如果服务端只认POST得话.
      

  3.   

    各位,我不是写程序的,有现成的我倒是可以照葫芦画瓢,照猫画虎,直接写我写不出来,谁闲来无事帮忙写一下。我找到的程序都是直接post的,hexMD5那段不知道怎么处理,请各位帮忙。
      

  4.   

    用HttpUnit,md5是提交个服务器的和你的客户端无关吧4.1.2  通过Get方法访问页面并且加入参数System.out.println("向服务器发送数据,然后获取网页内容:");
    //建立一个WebConversation实例
    WebConversation wc = new WebConversation();
    //向指定的URL发出请求
    WebRequest req = new GetMethodWebRequest( "http://localhost:6888/HelloWorld.jsp" );
    //给请求加上参数  
    req.setParameter("username","姓名");
    //获取响应对象
    WebResponse resp = wc.getResponse( req );//用getText方法获取相应的全部内容
    //用System.out.println将获取的内容打印在控制台上
    System.out.println( resp.getText() );4.1.3 通过Post方法访问页面并且加入参数System.out.println("使用Post方式向服务器发送数据,然后获取网页内容:");
    //建立一个WebConversation实例
    WebConversation wc = new WebConversation();
    //向指定的URL发出请求
    WebRequest req = new PostMethodWebRequest( "http://localhost:6888/HelloWorld.jsp" );
    //给请求加上参数  
    req.setParameter("username","姓名");
    //获取响应对象
    WebResponse resp = wc.getResponse( req );//用getText方法获取相应的全部内容
    //用System.out.println将获取的内容打印在控制台上
    System.out.println( resp.getText() );大家关注一下上面代码中打了下划线的两处内容,应该可以看到,使用Get、Post方法访问页面的区别就是使用的请求对象不同。
      

  5.   

    #4楼能给个具体代码吗?要求功能类似那段JS代码。
    md5是提交之前js运算得出的密码,是要post给服务器的。
    如果能实现完全的交互,那当然就不用关心md5了,md5会在提交之前自动运行。
      

  6.   


    能用PPPOE我就不这么费劲找代码了
      

  7.   

    虽然我不懂代码,不过貌似#4楼的代码也是直接post,不是交互输入用户名和密码再提交,所以也没有处理hexMD5代码段
      

  8.   

    用httpunit可以自动登录了,但是会打印页面信息,而且有错误。 
    怎么才能不打印任何信息? 
    import java.io.*;
    import java.net.*;import com.meterware.httpunit.*;
    import com.meterware.pseudoserver.*;
    import com.meterware.servletunit.*;public class WebLogin {    public static void main(String[] args) {        WebConversation webConversation = new WebConversation();        try {            WebResponse response = webConversation.getResponse("http://10.56.0.1/login");            WebForm form = response.getFormWithName("login");            form.setParameter("username","username");
                form.setParameter("password","password");            form.submit();        }        catch (Exception e) {
                e.printStackTrace();
            }    }}
      

  9.   

    错误信息如下: org.mozilla.javascript.EcmaError: TypeError: Cannot find function setInterval in object [object Window]. (httpunit#1) 
            at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654) 
            at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632) 
            at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660) 
            at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679) 
            at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3743) 
            at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2247) 
            at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214) 
            at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3143) 
            at script(httpunit:1) 
            at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487) 
            at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:178) 
            at org.mozilla.javascript.Context.evaluateString(Context.java:1104) 
            at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92) 
            at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88) 
            at com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151) 
            at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150) 
            at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131) 
            at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1132) 
            at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1034) 
            at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206) 
            at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:329) 
            at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3058) 
            at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:1994) 
            at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:907) 
            at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499) 
            at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452) 
            at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
            at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) 
            at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48) 
            at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271) 
            at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301) 
            at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285) 
            at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024) 
            at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179) 
            at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315) 
            at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526) 
            at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201) 
            at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183) 
            at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158) 
            at com.meterware.httpunit.WebResponse$Scriptable.setLocation(WebResponse.java:888) 
            at com.meterware.httpunit.javascript.JavaScript$Window.setLocation(JavaScript.java:343) 
            at com.meterware.httpunit.javascript.JavaScript$Location.jsSet_href(JavaScript.java:590) 
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
            at java.lang.reflect.Method.invoke(Method.java:585) 
            at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161) 
            at org.mozilla.javascript.ScriptableObject.putImpl(ScriptableObject.java:2109) 
            at org.mozilla.javascript.ScriptableObject.put(ScriptableObject.java:319) 
            at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.put(JavaScript.java:190) 
            at org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:1729) 
            at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1557) 
            at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1547) 
            at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3036) 
            at script.startClock(httpunit:2) 
            at script.x(httpunit) 
            at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2487) 
            at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164) 
            at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:398) 
            at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065) 
            at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162) 
            at com.meterware.httpunit.javascript.ScriptingEngineImpl.doEventScript(ScriptingEngineImpl.java:131) 
            at com.meterware.httpunit.scripting.ScriptableDelegate.doEventScript(ScriptableDelegate.java:70) 
            at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:819) 
            at com.meterware.httpunit.javascript.JavaScript.load(JavaScript.java:80) 
            at com.meterware.httpunit.javascript.JavaScriptEngineFactory.load(JavaScriptEngineFactory.java:62) 
            at com.meterware.httpunit.RequestContext.runScripts(RequestContext.java:44) 
            at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:159) 
            at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:125) 
            at com.meterware.httpunit.WebClient.getResponse(WebClient.java:96) 
            at WebLogin.main(WebLogin.java:17) 
    org.mozilla.javascript.WrappedException: Wrapped com.meterware.httpunit.ScriptException: Script 'var intervaltime; 
    intervaltime=window.setInterval(onTimer,1000); 
    function onTimer() 

    ...... 
    }     function openLogout() { 
            if (window.name != 'hotspot_status') return true; 
            open('http://10.56.0.1/logout', 'hotspot_logout', 'toolbar=0,location=0,directories=0,status=0,menubars=0,resizable=1,width=280,height=250'); 
            window.close(); 
            return false; 
        }