| Conditions | 6 |
| Total Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 2 |
| 1 | import socket |
||
| 9 | def local_ip(DEBUG=False): |
||
| 10 | ''' |
||
| 11 | return local ip of computer in windows by socket module and in unix with hostname command in shell |
||
| 12 | :param DEBUG: Flag for debug mode |
||
| 13 | :type DEBUG : bool |
||
| 14 | :return: local ip as string |
||
| 15 | ''' |
||
| 16 | try: |
||
| 17 | ip=socket.gethostbyname(socket.gethostname()) |
||
| 18 | if ip!="127.0.0.1": |
||
| 19 | return ip |
||
| 20 | elif platform.system()!="Windows": |
||
| 21 | command=sub.Popen(["hostname","-I"],stdout=sub.PIPE,stderr=sub.PIPE,stdin=sub.PIPE,shell=False) |
||
| 22 | response=list(command.communicate()) |
||
| 23 | if len(response[0])>0: |
||
| 24 | return str(response[0])[2:-4] |
||
| 25 | else: |
||
| 26 | return "Error" |
||
| 27 | else: |
||
| 28 | return "Error" |
||
| 29 | |||
| 30 | except Exception as e: |
||
| 31 | if DEBUG==True: |
||
| 32 | print(str(e)) |
||
| 33 | return "Error" |
||
| 34 | |||
| 53 |