0

I am using urllib2 to send a http request, and the request ip is the machine ip where I send the request. but I want to change the request ip to be another one, what should I do?

import urllib2

tmp_url = "http://test.com/load?num=1"
tmp_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"
tmp_refer = "http://a.test.com/"

tmp_header = {
    'User-Agent' : tmp_agent,
    'Referer' : tmp_refer
} 
tmp_request = urllib2.Request(tmp_url, None, tmp_header)
tmp_result = urllib2.urlopen(tmp_request)
print tmp_result.read()

could you give me some suggestion? thank you very much!

Mark
  • 422
  • 1
  • 5
  • 15
  • I don't see what you're getting at. What do you mean by 'Request IP'? If you want to send the request to a different server, use a different URL. If you're talking about the address of the machine running your script, then changing the Request IP will result in the response going to a different computer. –  Oct 29 '13 at 02:17
  • what I say is the latter, and I want to spoofing ip to send a http request, not malicious, I just want to test my program. – Mark Oct 29 '13 at 03:09

1 Answers1

1

Here is a quite related question which has been posted on SO and answered by @Alex Martelli. Take a look at this, hope it could give you some hints. :)

Community
  • 1
  • 1
fyr91
  • 1,253
  • 5
  • 17
  • 33