0

How can I spoof the user agent on demand in Internet Explorer via VBScript? There is a site I want to access that is intended for mobile only devices. My goal is to spoof an iOS mobile device. I need to be able to fake the agent, display the page, ad interact with it. Google is failing me.

TIA

user3108489
  • 363
  • 1
  • 4
  • 15

2 Answers2

1

This snippet of code connects to http://www.whatsmyua.com/ pretending to be an iPhone 6 and prints the output of the site:

Dim o : Set o = CreateObject("MSXML2.XMLHTTP")
o.Open "GET", "http://www.whatsmyua.com/", False
o.SetRequestHeader "User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
o.Send
WScript.Echo o.ResponseText

I didn't have an iPhone 6 to hand so I used this question to determine the user agent.

Community
  • 1
  • 1
Richard
  • 1,471
  • 7
  • 23
  • 47
  • Awesome! I'm not sure what I'm supposed to be looking for in the echo. How can I actually display a webpage with this to see how it behaves? Typically, I use the ie.navigate method, but not sure how to use in conjunction with this. – user3108489 Oct 03 '15 at 16:30
  • In case it matters, I plan to use w/Internet Explorer. Your example references Mozilla. – user3108489 Oct 03 '15 at 16:57
  • Ahh sorry, I thought you were looking for a vbscript solution (based on your tags) rather than something with IE. If you just want to browse a site on IE then you can just change the user-agent it broadcasts using the instructions at http://www.howtogeek.com/113439/how-to-change-your-browsers-user-agent-without-installing-any-extensions/ – Richard Oct 03 '15 at 19:24
  • The reference to "mozilla" in the code is part of the user agent string that the iPhone uses. Most browsers these days use that, even if they weren't made by the Mozilla Foundation. For more information see http://stackoverflow.com/questions/1114254/why-mozilla-string-is-present-on-all-browsers-user-agent – Richard Oct 03 '15 at 19:39
  • I definitely am looking for a vbscript solution. I came across that howtogeek site, but it looked like more of a manual setting that'd I'd have to set each time I want to do it and unset when I'm done to return to normal browsing. I'm looking for a way to programmatically (via vbscript & IE) set the user agent, navigate to URL, and perform actions. The part I have no experience with is setting the user agent via vbscript. Can this be done in a way that makes the browser window visible? For example, if I wanted to open m.google.com, how can I do that via vbscript on my PC? – user3108489 Oct 03 '15 at 20:04
  • Wondering if this may work... Setting and unsetting registry entry before and after I invoke ie.navigate. http://superuser.com/questions/660721/how-can-i-block-a-user-agent-string-in-ie11 – user3108489 Oct 03 '15 at 22:31
0

Managed to piece together a working solution to my prob (example using windows phone):

set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://whatsmyuseragent.com",0,0,0,"User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)"

Now this solution exists on the internet. lol

user3108489
  • 363
  • 1
  • 4
  • 15