gethostbyaddr в Python

C++ JAVA
Post Reply
newfag
Нов
Нов
Posts: 21
Joined: Wed Mar 28, 2012 9:17 am

gethostbyaddr в Python

Post by newfag » Fri Dec 21, 2012 12:21 pm

Здравейте, имам бот който е базиран на Python и искам да мога да видя хост-а записан на дадено IP.

Кода който ползвам е:

Code: Select all

# dns lookup
import re
import socket

@hook.command
def dns(inp):
    '''.dns hostname to perform dns lookup.'''
	
      try:
       return socket.gethostbyaddr(inp)
      except socket.herror:
         return "There was a problem solving the host. "

Не става и не става. Имам нещо подобно, което е дали сайта работи
и е горе-долу еднакъв скрипта, но работи ;'(


Code: Select all

import urlparse
from util import hook, http
@hook.command
def status(inp):
    '''.status <url> -- checks to see if the site is down'''

    if 'http&#58;//' not in inp&#58;
        inp = 'http&#58;//' + inp

    inp = 'http&#58;//' + urlparse.urlparse&#40;inp&#41;.netloc
    try&#58;
        http.get&#40;inp, get_method='HEAD'&#41;
        return inp + ' is currently 3online!'
    except http.URLError&#58;
        return inp + ' is currently 5offline!'
Някой да има идеи защо не става? Мерси предварително.

Edit: Смених скрипта на това

Code: Select all


import sys, socket, string, httplib, urlparse, urllib, re, urllib2, random, threading, cookielib
from xml.dom.minidom import parse, parseString
from time import sleep 
from util import hook, http

@hook.command   
def dns&#40;inp&#41;&#58;
 '.dns 5IP Reverse DNS for specified IP address. Example&#58; .dns 127.0.0.1 will return localhost'
  sites = &#91;inp&#93;
  appid = '01CDBCA91C590493EE4E91FAF83E5239FEF6ADFD'
  ip = socket.gethostbyname&#40;inp&#41;
  offset = 50
  num = 1
  while offset < 300&#58;
    url ="/xml.aspx?AppId=%s&Query=ip&#58;%s&Sources=Web&Version=2.0&Market=en-us&Adult=Moderate&Options=EnableHighlighting&Web.Count=50&Web.Offset=%s&Web.Options=DisableQueryAlterations" % &#40;appid,  ip,  offset&#41;
    conn = httplib.HTTPConnection&#40;"api.bing.net"&#41;
    conn.request&#40;"GET", url&#41;
    res = conn.getresponse&#40;&#41;
    data = res.read&#40;&#41;
    conn.close&#40;&#41;
    xmldoc = parseString&#40;data&#41;
    name = xmldoc.getElementsByTagName&#40;'web&#58;DisplayUrl'&#41;
    for n in name&#58;
      temp = n.childNodes&#91;0&#93;.nodeValue
      temp = temp.split&#40;"/"&#41;&#91;0&#93;
      if temp.find&#40;'www.'&#41; == -1&#58;
	sites.append&#40;temp&#41;
    offset += 50
	return 'Target&#58;' + inp 'IP&#58;' ip 'Reverse IP Lookup Total&#58;' len&#40;sites&#41;
domain&#40;s&#41;"&#41;&#41;
  for si in sites&#58;
    s.send&#40;"PRIVMSG %s &#58;%s%s%s%s%s%s\r\n" % &#40;chan,"&#91;",num,"/",len&#40;sites&#41;,"&#93; http&#58;//", si&#41;&#41;
    sleep&#40;2&#41;
    num += 1
  

Но ми дава грешка на линия 9, тоест

Code: Select all


sites = &#91;inp&#93;


Post Reply