Jump to content

AutoIT Script Converter


Recommended Posts

Python is SUPER. It's not hard to convert one to the other, but with Python, you have a choice of add in packages you can use for various things but in the end, the code is much different. I'll post a small sample from another thread where I posted a function that locates a running process.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

AutoIt runs out of the box in several flavours of Linux, under Wine. Currently supported are: Ubuntu, Debian, Fedora, MacOS (supported by WineHQ), and SUSE, Slackware, and FreeBSD (supported by the distros). Wine supports AutoIt3 and Scite (the script editor that also drives the AutoIt interpreter and compiler).

Edited by RTFC
Link to comment
Share on other sites

That depends entirely on the application. More importantly, why rewrite from scratch when you can just run/recompile the original?

Link to comment
Share on other sites

9 minutes ago, RTFC said:

AutoIt runs out of the box in several flavours of Linux, under Wine. Currently supported are: Ubuntu, Debian, Fedora, MacOS (supported by WineHQ), and SUSE, Slackware, and FreeBSD (supported by the distros). Wine supports AutoIt3 and Scite (the script editor that also drives the AutoIt interpreter and compiler).

Wine is not an option in this case, thank you for the note though.

Link to comment
Share on other sites

13 minutes ago, Earthshine said:

Python is SUPER. It's not hard to convert one to the other, but with Python, you have a choice of add in packages you can use for various things but in the end, the code is much different. I'll post a small sample from another thread where I posted a function that locates a running process.

I need to create a Python script that will read a txt file of ip addresses and convert them into hostnames.  That is my goal.  Thanks again.

Link to comment
Share on other sites

Just now, antmar904 said:

Thanks @Earthshine I actually just ran into the article!!

oops, you want the answers code

import socket
with open("test.txt", "r") as ins:
    for line in ins:
        print socket.gethostbyname(line.strip())

then use gethostbyaddr, no problem man. Carry on. Python rules.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

1 hour ago, Earthshine said:

oops, you want the answers code

import socket
with open("test.txt", "r") as ins:
    for line in ins:
        print socket.gethostbyname(line.strip())

then use gethostbyaddr, no problem man. Carry on. Python rules.

This is not working, I keep getting "NULL":

import socket
pfile = open ('/root/Desktop/ip.txt')
while True:
    IP = pfile.readline()
    try:
        host = socket.gethostbyaddr(ip.rstrip())
        print(IP,host)
    except:
        print(IP,"NULL")
pfile.close()

Here is the output:

 

Capture.PNG

Link to comment
Share on other sites

5 minutes ago, Earthshine said:

uh... I have to set up python. gimme a few, my dev vm should have it though.

Ok so I changed it to this and is working but I would like to output to another txt file and clean up the output a bit:

import socket
for IP in open('/root/Desktop/IP.txt').readlines():
  try:
    host = socket.gethostbyaddr(IP.rstrip())
    print(IP,host)
  except Exception as e:
    print(IP,"NULL")

Thanks again

Link to comment
Share on other sites

great work. now search google for what you want to do with python. I assume you could just pipe it at the command line? as for cleaning up there is plenty of string functions to get you by in Python. Happy programming and check back if your script is not working for assistance.

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

I changed the code a bit to stop when no more addresses are found.

import socket
pfile = open ('c:\\test.txt')
while True:
    ip = pfile.readline()
    try:
        host = socket.gethostbyaddr(ip.rstrip())
        print(host)
    except:
        break
pfile.close()

produces 

Quote

('whitestar.xxxxxxx.local', [], ['192.168.1.93'])
('BUILD1', [], ['192.168.1.34'])
[Finished in 0.2s]

Notice host is a passed back as a Dictionary so cleanup will involve working with that, like a hash in Perl

I named my dev vm WhiteStar because I love that old Sci-Fi series BABYLON 5 LOL

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

2 minutes ago, Earthshine said:

I changed the code a bit to stop when no more addresses are found.

import socket
pfile = open ('c:\\test.txt')
while True:
    ip = pfile.readline()
    try:
        host = socket.gethostbyaddr(ip.rstrip())
        print(host)
    except:
        break
pfile.close()

produces 

Notice host is a passed back as a Dictionary so cleanup will involve working with that, like a hash in Perl

thanks!

I got the same results with the extra character "[]" and removed it from the output:

import socket

for IP in open('/root/Desktop/ip.txt').readlines():
    try:
        host = socket.gethostbyaddr(IP.rstrip())
        hostname = host[0]
        print(IP.rstrip(),hostname)
    except Exception as e:
        print(IP.rstrip(),"NULL")

Output:

('1.1.1.1', 'hostname.domain')

('2.2.2.2', 'hostname.domain')

Link to comment
Share on other sites

Verified, your code works great. when it hots one that it cannot lookup it prints NULL, verified. you are good to go man. now compare that with the autoit code. you can see, you can do A LOT MORE with a lot less typing  with Python and C# and such.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

2 minutes ago, Earthshine said:

Verified, your code works great. when it hots one that it cannot lookup it prints NULL, verified. you are good to go man.

thanks again for pointing me in the right direction.

this is the first python script I've played with.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...