Page 1 of 1

Kali Linux on Virtualbox and using Python code

Posted: 10. Nov 2019, 06:17
by coolcassie
Hi,

This is my first time posting on the forum so I wasn't entirely sure if this was in the right section of the forums.

I'm doing work for an assignment and have been using Kali Linux on VirtualBox. The part I'm unsure of is using Python coding in this and how to call the file to run the Python code.
We've been given instructions to create a Bin folder which I've done and these are the other instructions for the first part:

Create the file "listip.py" in the "bin" folder and enter the text from above into that file.
Set the execute permission on that file with the command: chmod o+x ~/bin/listip.py
Test to see if it works using the command: ~bin/listip.py x.x.x.x/n
(where x.x.x.x/n is the IP address of your target virtual machine)

This is the code they've given for the first one:

Code: Select all

#!/bin/python
import sys, os
if len(sys.argv) == 2 :
 os.system("nmap -n -sn -oG - " + sys.argv[1] + "|head -n -1|tail -n +2|cut -d' ' -f2")
exit()
Is there anything wrong with the code maybe?

There is more parts to this but wanted to try and work out how to do this part first.

Can anyone help or suggest what I should try out?

Re: Kali Linux on Virtualbox and using Python code

Posted: 10. Nov 2019, 08:26
by socratis
coolcassie wrote:This is my first time posting on the forum so I wasn't entirely sure if this was in the right section of the forums.
Welcome! And don't worry, we can move things around to place them where they belong... ;)
coolcassie wrote:The part I'm unsure of is using Python coding in this and how to call the file to run the Python code.
You got to understand that we can't be helping you with your assignment, or your Python programming, this is a VirtualBox site. If we were to start giving advice on things like that, the situation would get out of had really quickly. All we could help you with is VirtualBox related questions.
coolcassie wrote:This is the code they've given for the first one
Your Python script in a sense is trying to run:
  • nmap -n -sn -oG - N.N.N.N
coolcassie wrote:Is there anything wrong with the code maybe?
Not the place to ask, you should try a Python forum in general, and/or an "nmap" forum, again generally speaking.

I don't see a VirtualBox-related question in your post. Is there anything that I'm missing?

Re: Kali Linux on Virtualbox and using Python code

Posted: 10. Nov 2019, 14:30
by fth0
coolcassie wrote:Set the execute permission on that file with the command: chmod o+x ~/bin/listip.py
Test to see if it works using the command: ~bin/listip.py x.x.x.x/n
In the 2nd line quoted above, there is a '/' missing in the underlined part.