Bash script who maps IP with MAC address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script who maps IP with MAC address
# 8  
Old 11-02-2017
RedHat

Quote:
Originally Posted by RudiC
Not sure I understand...?
These two lines are OK , i can see them on the screen.

What i want to do is :
These two lines should be inside my firewall and not just displayed on the screen (netfilter 'iptables')

if i use the following command in order to see all the FORWARD rules:

Quote:
#iptables -L FORWARD
i should see the result (the two lines of your code )

Quote:
iptables -I FORWARD -s 192.168.0.10 -m --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT
iptables -I FORWARD -s 192.168.0.11 -m --mac-source aa:aa:aa:aa:aa:aa -j ACCEPT

Actually when i launch the command

Quote:
#iptables -L FORWARD
Chain FORWARD (policy DROP)
target prot opt source destination
DROP udp -- anywhere anywhere udp dpts:1024:65535
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED

I should see two more lines -Smilie

Last edited by hermouche; 11-02-2017 at 12:26 PM..
# 9  
Old 11-02-2017
Sorry I'm not too familiar with iptables - did you try to just execute the two lines? Redirect into a temporary file, and then source that in your root shell.
# 10  
Old 11-03-2017
Quote:
Originally Posted by RudiC
Sorry I'm not too familiar with iptables - did you try to just execute the two lines? Redirect into a temporary file, and then source that in your root shell.
YES exactly i want to execute these two lines hopefully -Smilie
If i launch manually the two lines (one by one) it will do the work.

So now how to include them into the bash script !!!

I Think you got my point.

How to redirect into a temporary file, and then source the root shell ?

Thanks again RudiC.

---------- Post updated 11-03-17 at 09:57 AM ---------- Previous update was 11-02-17 at 10:31 AM ----------

Hy everybody an RudiC

I am bothering you but i want to learn from you. Just newbee to scripting Image

So far, with the big help of "RudiC", i got the script and it works just fine, thanks again "RudiC"

This is what i've done but seem's not professional at all !!!



Quote:
#!/bin/bash

# I should at first create a file which has two columns : one for IP addresses and the second the corresponding MAC address . The file is called "ipmacmap".

# Create an executable file called "forward.sh"
echo '#!/bin/bash' > forward.sh
chmod +x forward.sh


# Lauching the following command will edit the previous "forward.sh" with forwarding rules for evey corresponding IP vs MAC address from "ipmacmap"

sed 's/ / -p tcp -m multiport --dports 110,143,25,465,585,993,995,80,443 -m mac --mac-source /; s/^/iptables -I FORWARD -s /; s/$/ -j ACCEPT/' ipmacmap >> forward.sh


# Applying the forward rules
./forward.sh

# Check the rules
iptables -L FORWARD --line-numbers
How to be more professional !
Is it possible to include the file "ipmacmap" inside the script?
Any other ideas are welcomed Image

Thanks for helping me.

Red

Last edited by hermouche; 11-02-2017 at 01:06 PM..
# 11  
Old 11-03-2017
You are welcome. It's always good and satisfying to see people learn and become creative.

Now, to your script. If it works as intended, that's fine, be it professional or not. Congrats!

Of course, it might benefit from some polishing. When I proposed to "source" the file, I meant that - not execute a new script in a subshell. Look up source in man bash. No copying #!/bin/bash to the file, no chmod - much less hassle.
When you want to "iinclude the file "ipmacmap" inside the script", do you mean creation of the file? Yes, that can be done, but: please don't raise vague enquiries but post hard facts: sample input data, desired output, the logics connecting the two, preferred tools, versions, etc. While in your case the output seems to be already defined, it mayhap could be reconsidered to better fit into the overall process.
# 12  
Old 11-04-2017
Agree with you RudiC.

Thanks for your good job Smilie

Red
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a value to a physical memory address in bash script?

How would I write a value to a physical memory address? I was able to read a physical memory address (for example, 0x400) using this line: dd if=/dev/mem count=4 bs=1 skip=$(( 0x400 )) But I get an error: dd: 'standard input': cannot skip to specified offset when I try to write using... (1 Reply)
Discussion started by: rabrandt
1 Replies

2. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies

3. Shell Programming and Scripting

Script extracting ip address from MAC wifi card

Hi Everybody, Goal: From my backup box on my local network, knowing the Wifi MAC address of my laptop, I would like to dynamically identify which ip address is attributed to my laptop. The aim is to store this ip address in a local variable and that this information is retrieved by another... (11 Replies)
Discussion started by: freddie50
11 Replies

4. Shell Programming and Scripting

IP Address LookUp Bash Script

I am new to bash scripting. I want write a script that reads from the first argument file and run nslookup, then prints out each nslookup. Something like below: File name = ip 8.8.8.8 8.8.4.4 Bash shell script: nslookup.sh #!/bin/bash for i in $1 do nslookup $i done I... (7 Replies)
Discussion started by: boldnbeautiful
7 Replies

5. OS X (Apple)

OpenStreetMap client (with offline maps) for Mac OS X

Hi I am searching for an OpenStreetMap client (with offline maps) for Mac OS X. Like Google Earth client, but with offline maps. (2 Replies)
Discussion started by: slashdotweenie
2 Replies

6. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

7. Shell Programming and Scripting

bash: convert mac address to 16 character format

Hi there Im not quite sure how i can do this, but i am retrieving the mac address from boxes, which in some instances is arriving in its shortened format (i.e. dropping the leading zeros)... for example 0:3:BA:1:E:84 Im trying to figure out a way of converting the single character... (3 Replies)
Discussion started by: rethink
3 Replies

8. Shell Programming and Scripting

trim last octate of ip address using bash script

Hi, i need to replace the last octate in ipaddress with 0 using bash shell for one of my applicatiom. googling i found the below link where they do the same thing but use long2 ip which i dont see in linux. trim ip address octet - Stack Overflow Plz can soemone guide how do i do this... (5 Replies)
Discussion started by: akshatha
5 Replies

9. Shell Programming and Scripting

script to compare two files of mac address

Hi I need to write a bash shell script. I have two separate text files. One file contains a list of MAC addresses taken from a network scan, the other contains a list of MAC addresses for our currently-managed devices. How can I compare these two files, and output a list of addresses that have... (6 Replies)
Discussion started by: borderblaster
6 Replies

10. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies
Login or Register to Ask a Question