{"id":297,"date":"2011-09-10T10:15:28","date_gmt":"2011-09-10T09:15:28","guid":{"rendered":"http:\/\/www.floyd.ch\/?p=297"},"modified":"2023-05-31T08:43:23","modified_gmt":"2023-05-31T07:43:23","slug":"detect-shared-hosting-with-bing","status":"publish","type":"post","link":"https:\/\/www.floyd.ch\/?p=297","title":{"rendered":"Detect shared hosting with Bing"},"content":{"rendered":"<p>Bing has a pretty cool <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/bing\/search\/ff795671(v=msdn.10)?redirectedfrom=MSDN\" title=\"IP advanced search operator\" target=\"_blank\" rel=\"noopener\">IP advanced search operator<\/a>. It can be used to detect shared hosting. It is quite annoying to type in each IP manually when you have to check several IPs (e.g. corporate IP network). The following script will scan an entire range of IPs. The examples below (Google IPs 74.125.39.103 to 74.125.39.106) give some pretty interesting results&#8230;<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef printBingSharedHosting(ip_start, ip_end):\r\n    import urllib2\r\n    import re\r\n    \r\n    bing_url = 'http:\/\/www.bing.com\/search?q=ip%3A'\r\n    no_results_string = &quot;No results&quot;\r\n    \r\n    def bing_shared_hosting_get_matches(response):\r\n        regex = '&lt;h3&gt;&lt;a\\shref=&quot;(.*?)&quot;\\sonmousedown=&quot;'\r\n        mo = re.finditer(regex, response)\r\n        urls = &#x5B;]\r\n        for i in mo:\r\n            urls.extend(i.groups())\r\n        return urls\r\n    \r\n    def bing_shared_hosting_query_bing(ip_str):\r\n        body = urllib2.urlopen(bing_url+ip_str).read()\r\n        if not no_results_string in body:\r\n            for i in bing_shared_hosting_get_matches(body):\r\n                result(ip_str+&quot; : &quot;+i)\r\n        else:\r\n            error(&quot;Bing page did not show '&quot;+no_results_string+&quot;' for ip: &quot;+ip_str)\r\n\r\n    info(&quot;Starting bing shared hosting search. I'm not printing anything until i find something&quot;)\r\n    info(&quot;This method is only searching through the first result page of bing!&quot;)    \r\n    for ip in getIpRangeList(ip_start, ip_end):\r\n        bing_shared_hosting_query_bing(ip)\r\n\r\n\r\ndef getIpRangeList(ip_start, ip_end):\r\n\r\n    result_list = &#x5B;]\r\n\r\n    one, two, three, four = ip_start.split('.')\r\n    one, two, three, four = (int(one), int(two), int(three), int(four))\r\n    end_one, end_two, end_three, end_four = ip_end.split('.')\r\n    end_one, end_two, end_three, end_four = (int(end_one), int(end_two), int(end_three), int(end_four))\r\n\r\n    while one &lt;= end_one:\r\n        end_two_tmp = end_two\r\n        if not one == end_one:\r\n            end_two_tmp = 255\r\n        while two &lt;= end_two_tmp:\r\n            end_three_tmp = end_three\r\n            if not two == end_two:\r\n                end_three_tmp = 255\r\n            while three &lt;= end_three_tmp:\r\n                end_four_tmp = end_four\r\n                if not three == end_three:\r\n                    end_four_tmp = 255\r\n                while four &lt;= end_four_tmp:\r\n                    result_list.append(&quot;%i.%i.%i.%i&quot;%(one, two, three, four))\r\n                    #debug(str(one)+&quot; &quot;+str(two)+&quot; &quot;+str(three)+&quot; &quot;+str(four))\r\n                    four += 1\r\n                four = 0\r\n                three += 1\r\n            three = 0\r\n            two += 1\r\n        two = 0\r\n        one += 1\r\n    \r\n    return result_list\r\n\r\n   \r\ndef error(*text):\r\n    print &quot;&#x5B;PY-ERROR] &quot;+str(&quot; &quot;.join(str(i) for i in text))\r\n    if SLEEP_TIME_ON_ERROR &gt; 0:\r\n        sleep(SLEEP_TIME_ON_ERROR)\r\n\r\ndef result(*text):\r\n    print &quot;&#x5B;PY-RESULT] &quot;+str(&quot; &quot;.join(str(i) for i in text))\r\n\r\ndef info(*text):\r\n    print &quot;&#x5B;PY-INFO] &quot;+str(&quot; &quot;.join(str(i) for i in text))\r\n\r\ndef debug(*text):\r\n    print &quot;&#x5B;PY-DEBUG] &quot;+str(&quot; &quot;.join(str(i) for i in text))\r\n\r\nprintBingSharedHosting(&quot;74.125.39.103&quot;, &quot;74.125.39.106&quot;)\r\n<\/pre>\n<p>I admit, the getIpRangeList function could be a little bit more elegant, but I didn&#8217;t want to use an external library, didn&#8217;t find any suitable code snippet and in the end, it does its job.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bing has a pretty cool IP advanced search operator. It can be used to detect shared hosting. It is quite annoying to type in each IP manually when you have to check several IPs (e.g. corporate IP network). The following &hellip; <a href=\"https:\/\/www.floyd.ch\/?p=297\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,19],"tags":[22,20,23],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-coding","category-useful-scripts","tag-bing","tag-python","tag-shared-hosting"],"_links":{"self":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":9,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":1370,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/1370"}],"wp:attachment":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}