2

This answer told me about http://ip.42.pl/raw, which provides the (to my knowledge) simplest way of getting my own IP using requests in python 2.7. It just displays one sting with the desired information and nothing else.

Are there any websites that display a request's user agent header in a similar slim/lightweight way (just one string containing the UA header, no graphics, no fancy buttons, no ads, nothing)?

I did some google searches, but all sites that come up are bloated with ads and graphics.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114
sudonym
  • 3,788
  • 4
  • 36
  • 61
  • 1
    Note that any such site is just going to tell you the user agent that `requests` is sending, which you can check locally just as easily, and which won't tell you anything about what a different `requests`-based program is sending, or `curl`, or your browser, so it's not all that useful. – abarnert Jun 18 '18 at 03:41
  • Also, what sites are you finding that are bloated with ads and graphics? None of the first few results I found on either DDG or Google were like that. Even with my ad blocker disabled, some had no ads, others had 1-2 unobtrusive ads after the content. If you're seeing something a lot worse than that on the same sites, your browser may be infected or something. – abarnert Jun 18 '18 at 03:59
  • ur right, we need a thing like this, ridiculously hard to find! – colin lamarre Jul 12 '22 at 00:44

2 Answers2

1

I don't know of any websites that do it, but here's how to do it yourself in code:

import requests
headers = requests.utils.default_headers()
print (headers['User-Agent'])
John Gordon
  • 29,573
  • 7
  • 33
  • 58
1

I don't know of a page that delivers a single-line answer. There are a number of pages like whatsmyua and whatsmyuseragent, or you can just ask Google my user agent. None of these seem bloated with adds or graphics—but they all do require a trivial bit of parsing. For example:

>>> page = requests.get('http://whatsmyuseragent.org/')
>>> soup = BeautifulSoup(page.text, 'lxml')
>>> print(soup.p.text)
python-requests/2.18.4

See it in action at repl.it.

However, there may not be much point in doing this.

Asking for your IP is useful, because your computer may not know its own public IP. For example, I'm behind a NAT router, so my computer thinks it's at 10.0.1.100, but my router forwards my requests as some other dynamic IP address assigned by my ISP. So, if I want to give you my address to connect to me, I need to ask my router, or ask someone on the internet what they see when I connect.

Asking for your user agent is not likely to be as useful. Even if you're behind a transparent proxy on a work or school network, very few of them are configured to change your user agent. So, your user agent is almost certainly going to be whatever you set it to, or whatever the defaults are for the library you use—see John Gordon's answer for requests.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • @sudonym Sorry; try it now. (Also, this question got me to notice that my `requests` was out of date, so thanks. :) – abarnert Jun 18 '18 at 04:29
  • 1
    @sudonym On what line? And what versions of `requests` and `BeautifulSoup` do you have? When I run this with recent versions of both (in both Python 3.7 and 2.7), it prints the text listed in the answer. – abarnert Jun 18 '18 at 04:34
  • 1
    @sudonym I added a link to an online interpreter to show that it works. – abarnert Jun 18 '18 at 04:36
  • Updated bs4 and lxml and now it works like a charm - that was what I was after. Many thanks! – sudonym Jun 18 '18 at 04:42