M@xliner Site

Share idea and testing software open source free


ใส่ความเห็น

วิธีแก้ไขให้โหลดผ่าน Proxy

โหลดผ่าน proxy

หากต้องใช้ proxy ในการโหลด ต้องมีการระบุตัวแปร ‘http_proxy’ ไว้ใน shell ก่อนรันคำสั่ง เช่น IP ของ proxy คือ 192.168.1.1 และพอร์ต proxy คือ 3128 ถ้าใช้ BASH สามารถทำได้โดย

$ export http_proxy=http://192.168.1.1:3128

ใช้คำสั่ง wget พร้อมระบุออปชั่น ‘–proxy’ เพื่อให้โหลดผ่าน proxy

$ wget --proxy 'http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso' --2010-01-22 14:30:26--  http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso
Connecting to 192.168.1.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 724097024 (691M) [application/octet-stream]
Saving to: `Fedora-11-x86_64-Live.iso'
 0% [                                                                                     ] 63,434      96.4K/s

แต่ถ้า proxy ต้องระบุ user, password ด้วย จะขึ้น error ดังนี้

$ wget --proxy  'http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso' --2010-01-22 14:31:06--  http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso
Connecting to 192.168.1.1:3128... connected.
Proxy request sent, awaiting response... 407 Proxy Authentication Required
2010-01-22 14:31:06 ERROR 407: Proxy Authentication Required.
ใช้ออปชั่น '--proxy-user' และ '--proxy-password' เพื่อระบุ user, password ในการใช้ proxy
$ wget --proxy-user=prxuser --proxy-password=prx1234  'http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso' --2010-01-22 14:30:26--  http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso
Connecting to 192.168.1.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 724097024 (691M) [application/octet-stream]
Saving to: `Fedora-11-x86_64-Live.iso'
 0% [                                                                                     ] 63,434      96.4K/s

ไฟล์คอนฟิก .wgetrc

แทนที่จะต้องระบุออปชั่น proxy ทุกครั้ง สามารถสร้างเป็นไฟล์คอนฟิกสำหรับใช้คำสั่ง wget โดยสร้างไฟล์ชื่อ .wgetrc (มีเครื่องหมายจุดนำหน้าชื่อไฟล์ด้วย) ไว้ใน HOME ของผู้ใช้งาน

$ cat ~/.wgetrc http_proxy=http://192.168.1.1:3128/
proxy_user=prxuser
proxy_password=prx1234

หลังจากสร้างไฟล์คอนฟิก .wgetrc แล้ว เวลาใช้คำสั่ง wget ก็ไม่ต้องระบุออปชั่นใดๆ อีก

$ wget  'http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso' --2010-01-22 14:37:46--  http://www.mirror.in.th/osarchive/fedora/releases/11/Live/x86_64/Fedora-11-x86_64-Live.iso
Connecting to 192.168.1.1:3128... connected.
Proxy request sent, awaiting response... 200 OK
Length: 724097024 (691M) [application/octet-stream]
Saving to: `Fedora-11-x86_64-Live.iso.1'
 0% [                                                                                     ] 80,810      95.8K/s

>> Cntlm Authentication Proxy

ข้อมูลอ้างอิง : SpaLinux