1

I have a Python code that connects to MongoDB and extracts data - when I print the same I get the below output:

data =  db.collection.aggregate(...)

for d in data:
       ip = d['_id']
       print d , ip


{u'count': 125391, u'_id': u'11.11.11.111'} 11.11.11.111
{u'count': 994883, u'_id': u'11.11..11.112'} 11.11..11.112
..............................................

But when I try to get the hostname for the IP listed in each records I get the below error:

name,alias,addresslist = socket.gethostbyaddr(ip)

Traceback (most recent call last):
  File "./myprog.py", line 51, in <module>
    name,alias,addresslist = socket.gethostbyaddr(ip)
socket.herror: [Errno 0] Resolver Error 0 (no error)
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Programmer
  • 8,303
  • 23
  • 78
  • 162

1 Answers1

0

11.11.11.111, etc. do not look like valid ip addresses, so that would be the first issue I think you should try solving.

Where are these ip addresses coming from?

Bartek
  • 15,269
  • 2
  • 58
  • 65
  • Well I just gave a dummy value the values are correct and when I do a nslookup of that IP I do get a valid correct result – Programmer Apr 09 '16 at 01:53
  • @Prakash You sure? $ nslookup 11.11.11.111 Server: 192.168.1.1 Address: 192.168.1.1#53 ** server can't find 111.11.11.11.in-addr.arpa.: NXDOMAIN – Bartek Apr 09 '16 at 01:57
  • As stated I have dummy IP values - 11.11.11.111 - in actual I get valid one only. I found more about issue and fix in http://stackoverflow.com/questions/7832264/difficulty-using-pythons-socket-gethostbyaddr however at one point of time I am again facing this error - socket.error: wildcard resolved to multiple address – Programmer Apr 09 '16 at 02:04
  • @Prakash, if your IP addresses are valid than there shouldn't be any problem with validation. It's not a MongoDB issue. I'd suggest you to update your post with minimum viable and reproducible solution. Providing a dummy value will not help anyone. For testing purpose, try using google.com ip address and see if it works. – Saleem Apr 09 '16 at 03:22