2012-01-01 64 views
0

我需要在小時基礎上在路由器上釋放我的IP地址。路由器頁面需要簡單的認證和點擊按鈕來完成這個過程。這些都是HTTP調用:在OSX中自動執行HTTP GET/POST

身份驗證

GET /RST_st_dhcp.htm HTTP/1.1 
Host: 10.10.1.1 
Authorization: Basic YWRtaW46cGFzc3dvcmQ= 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 

釋放按鈕點擊

POST /st_dhcp.cgi?id=1044071018 HTTP/1.1 
Host: 10.10.1.1 
Content-Length: 31 
Cache-Control: max-age=0 
Authorization: Basic YWRtaW46cGFzc3dvcmQ= 
Origin: http://10.10.1.1 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7 
Content-Type: application/x-www-form-urlencoded 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Referer: http://10.10.1.1/RST_st_dhcp.htm 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 

connect=Release&refreshScrn=yes 

這怎麼OSX中實現自動化?是否有可能爲此編寫自動化腳本?

回答

-1

您可以簡單地使用curl,使該請求 - 像

curl -e http://10.10.1.1/RST_st_dhcp.htm \ 
    -d 'connect=Release&refreshScrn=yes' -u user:password \ 
    'http://10.10.1.1/st_dhcp.cgi?id=1044071018' 

你需要檢查是否在URL事項id。如果沒有,上述應該是你所需要的。如果確實如此,那麼您可能必須提出第一個請求,以從其有效載荷中獲取id